Lower bounded wildcards can be used to make a variable less restrictive.

* Lower bounded 하한 a variable 변수 restrictive 제한적인 less 덜

 

For example, the following method will only accept collections of type List<Integer>

public void method(List<Integer> list){
	...
}

 

Using a lower bounded wildcard ?, we can modify the method to accept any List which contains Integer or any class which is a superclass of Integer :  

* accept 수용하다

 

public void method(List<? super Integer> list){
	...
}

 

This method will now accept Lists of supertypes of Integer, such as Number and Object.

'Java - English ver' 카테고리의 다른 글

Writing genenric methods  (0) 2024.11.05
Wildcards Extras  (0) 2024.11.04
Upper bounded wildcards  (0) 2024.10.31
Using unbounded wildcards  (1) 2024.10.30
Wildcards vs OBjects  (0) 2024.10.29

+ Recent posts