Java Code:
class First {}
class Second extends First {}
class Jinkies<T> {}
interface Greeting<T> {}
class Hello<U extends T, T> implements Greeting<T> {
private Map<Jinkies<U>, List<U>> scooby;
}
In the announcement scooby, both Jinkiesand Listhave the same type parameter - this is what I want to provide. Is there a way to do this in Java, without the transfer of the two parameters ( Uand T) in the class declaration Hello?
I would like to have only one - for example. sort of:
class Hello<U extends T> implements Greeting<T>
however, this does not compile. I have to write:
new Hello<Second, First>()
instead:
new Hello<Second>()
although I donβt care Firstanywhere in the body Hello(as well as users Hello).
Edit - as @LouisWasserman explains in the comment, the bad example on my part is above. Maybe clarify - let's say I always want to do:
new Hello<First>()
U, U extends First (.. First Second ) Hello, First , U . , :
void method1(U a) {}
void method2(U b) {}
, U U , not , (.. First Second), .
<U extends T> void method1(U a) {}
<U extends T> void method2(U b) {}
, method1(first) method2(second).
- , , , -. , . , First, "" Third. Second, "" Zero. ...