Java Study Notes 10 -- generic summary, java Study Notes 10 -- generic
Java learning notes series:
Java study notes 9-internal class Summary
Java study note 8-interface Summary
Java study notes 7 -- abstract classes and abstract methods
Java study Note 6-class inheritance, Object class
Java study notes 5-Class Method
Java study note 4-object initialization and collection
Java Study Notes 3-Basics of classes
In software development, collections are inevitably used, and collections in C # represent arrays and several collection classes. Whether they are arrays or collection classes, they have their own pros and cons. How to use a good collection is a skill we must master in the development process. Do not underestimate these techniques, and once you have used the wrong set or approach to the collection in development, the application will run away from your expectations.
Recommendation 20: Use
1 Basic concepts of generic programmingGeneric programming:Writing programs that do not depend on specific data typesAbstract the algorithm from a specific data structure to become a universalC + + templates provide a key foundation for generic programmingTerminology: ConceptsUsed to define the type of data with a certain function. For example:The concept of "can be compared to all data types (with comparis
Using System;Using System.Collections.Generic;Using System.Text;
Namespace Genericity{Class Program{Generic Class 1:public class Genericityhello{public void SayHello (T-t){Console.WriteLine (T.tostring ());}}
Generic class 2:public class Genericityhello1{Private T TT;
Public T TT{Get{return TT;}Set{tt = value;}}
public void SayHello (){Console.WriteLine (TT. ToString ());}}
public class 中文版{public override
Database objects are instantiated using Hibernate and JPA in the project, but the resulting method does not support a multi-conditional query. It can be cumbersome to encode multi-conditional queries against each database object, and these methods may need to be re-encoded once the table structure changes in the future. So consider writing a method that makes a multi-conditional query on a database object and returns a generic object, which makes it e
First, IntroductionReview Javac The compilation process of the solution syntax sugar when you see the generic erase in the example, the information on the Internet is mostly more specific, in this make their own some detailed and understandable summary.Ii. Introduction of generic typeGenerics are a new feature of JDK 1.5, a paradigm used by compilers, a kind of syntax sugar that guarantees type safety. Note
Generic and generic sets in C,
1. What is generic?
Generic is a new function in the C # language and the Common Language Runtime Library (CLR). It introduces the concept of type parameters to. NET Framework. Type parameters make it possible to design certain classes and methods. For example, by using the
. NET generic 02, generic usage,. net02
In ". NET generic 01, why do you need generic and generic basic syntax", I learned about the basic concepts of generic. This article focuses on the use of
Differences between generic and non-generic types ., Differences between generics
Generic setLisit Advantages1. High PerformanceNon-generic collection classes are used for value types. When converting a value type to a reference type or converting a reference type to a value type, you need to bind and unbox the value t
compilation type of the object is changed to the object type, but its run-time type is still its own type.2. As a result, it is necessary to//1 the collection element into the specific target type, and the "java.lang.ClassCastException" exception can easily occur.So is there any way that the collection can remember the types of elements within the collection and be able to achieve the "java.lang.ClassCastException" exception when the runtime does not have a problem at compile time? The answer i
The essence of generics is to parameterize the data type, the value of the input parameter of the normal method can be changed, but the type (for example: String) is immutable, it makes it possible to overload the method in the face of different types of input parameters. Generics simply make this data type as variable as the value of the parameter.Generics are divided into generic interfaces, generic class
What is the difference between an array and a generic container
To differentiate between arrays and the functionality of a generic container, there are three concepts to understand: covariance (covariance), contravariance (contravariance), and extraneous (invariant).
If Class A is a subclass of class B, it is recorded as a a≦b. With a transform f (), if:
When A≦b, there is f (a) ≦f (B), then the tr
Document directory
Introduction:
1. Define a generic class
2. Define Constraints
Reference
Introduction:
Since the birth of generics, the love of many object-oriented programmers is generally higher than that of other data structures. :). However, the support of various object-oriented programmers is not the same. In CPP, static compilation is used, that is, the compiler determines the generic type,
Resistance to changes and coordination of generic interfaces, generic interfaces and coordination
1. covariant of generic Interfaces
If the generic type is marked with the out keyword, the generic interface is the covariant. This also means that the return type can only be T
Java basics-generic 2, basic generic java6. Speculation
The java compiler can check all method calls and corresponding declarations to determine the real parameters of the type, that is, type speculation. The speculative algorithm of the type determines the most specific types of all parameters, as shown in the following example:
// Declaration of generic methods
First look at the description of the type aliases in the Spring.net operating manual 4.12.3. Registering type aliasesAs a substitute for the full name of the type, the type alias simplifies the spring.net configuration file. Aliases can be registered in the config file, or can be registered programmatically, and can be used anywhere in the object definition where the full name of the type is required. You can also define type aliases for generic clas
http://blog.163.com/chenhui_761217/blog/static/340737792010912103043831/
How to understand the default () method:
The default keyword is used because it is necessary to assign an initial value to an object instance without knowing whether the type parameter is a value type or a reference type. Consider the following code:
Class testdefault{Public T foo (){T t = null; //???return t;}}
if we bind a generic argument with an int, then T is an int, then th
. NET Framework System. Array. Sort Array class, deepen understanding of IComparer, IComparable, generic delegate, anonymous method, Lambda expression, Generic ArrayContent
Custom class
Array. Sort
References
System. Array. Sort has many set operations, such as sorting, searching, and cloning. You can use this class to deepenIComparer, IComparableUnderstanding of
Java generic and java generic1. Understanding of generics
Generic is a new feature of JDK1.5. In essence, generic is a parameterized type, that is, the operated data type is specified as a parameter. This type of parameter can be used in the creation of classes, interfaces, and methods. They are called generic classes,
The Java programming idea says:A generic class is applied across a class, but it can include a parameterized method in the class, and the class can be generic or not generic, that is, whether there is a generic method that has no relation to whether the class in which it resides is a
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.