- When inheriting the method of implementing an interface, if the generic interface directly specifies the type without subsequent casts, this directly represents the type, and the parameter is the type
- 1
public
static
void
up (list<?
extends
number> l) {
//method implementation}
- 1
public
Static
void
down (list<?
super
number> l) {
//method implementation }
- Generic Erase
12 |
List<Integer> l1 = new ArrayList<Integer>(); List l2 = l1; |
- Map cannot traverse the for loop directly because the interface is not implemented
- List wildcard lsit<?> generally as a method parameter does not indicate what type is not yet known, can receive all the list
- If you add the same key in the map, overwrite the previous
- Collections: The tool Class of the collection: it contains the methods of sorting, finding, exchanging elements, and getting synchronized set objects; See API for details;
- Arrays:
1 |
public static <T>List<T> asList(T ... t){} |
returns a fixed-length list set, and a T array element that consists of a list collection element; The returned list collection length cannot be changed, otherwise, an error occurs;
12345678910111213 |
int
[] arr = {
1
,
2
,
3
};
List<Integer> l1 = Arrays.asList(arr);
//ERROR
List<
int
[]> l2 = Arrays.asList(arr);
//YES
Integer[] arr1 = arr;
//ERROR
Integer[] arr1 = {
1
,
2
,
3
};
List<Integer> l3 = Arrays.asList(arr1);
List <----> 数组
List-->数组: Collection接口里的 Object[] toArray();
List l =
new ArrayList();
l.add(
1
);
l.add(
"a"
);
l.add(
false
);
Object[] arr= l.toArray();
|
- generics: Simple to use (must be mastered):
123 |
List list = new ArrayList(); String ele = (String)set.get( 0 ); List<String> list = new ArrayList<String>(); |
indicates that the set collection can only be loaded as a string type element;
1 |
String ele = set.get( 0 ); |
at the bottom are still:
1 |
String ele = (String)set.get( 0 ); |
123456789 |
Map<String,Date> map =
new HashMap<String,Date>();
map.put(
"A"
,
new Date());
Set<Map.Entry<String,Date>> entrys = map.entrySet();
//取出Map里所有Entry对象
Iterator<Map.Entry<String,Date>> it = entrys.iterator();
//使用迭代器
//迭代出每一个Entry对象
while
(it.hasNext()) {
Map.Entry<String,Date> entry = it.next();
//取出每个entry里的 key和 value
String key = entry.getKey();
Date value = entry.getValue(); }
//show(new HashMap<>());
|
- Generic method://The declaration placeholder for a generic method can only be placed in front of the method return type;
1 |
public static <T> List<T> asList(T ... t){ } |
Static methods of arrays change some mutable parameters to list objects
- get classname permissions named class bytes static method for code object class
1 |
static class<?> forname (String className) |
Represents all types that are indeterminate and can accept all types; But you can't add elements to it
- The upper and lower limits of the list<> cannot be used simultaneously
- The delimiter for a generic file path uses "/" to be compatible with multiple platforms, "\ \" generally only supports Windows
- Generally using the file file class to create files does not specify the path is the abstract path is the bin directory, the default is created below
Java Basic Learning Note "08" Generics-qualified, generic operation