NetBeans wrote:incompatible types: invalid method reference
incompatible types: Shape cannot be converted to Round
"Il y a peu de choses qui me soient impossibles..."
"Il y a peu de choses qui me soient impossibles..."
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Jeanne Boyarsky wrote:The method reference has the same amount of information as my second example. Which shows that Java needs more context than the method reference can provide.
"Il y a peu de choses qui me soient impossibles..."
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Stevens Miller wrote:if both have the same erasure?
Paul Clapham wrote:
But they don't. In the first example the type variable T means the same thing in both places, Class<T> and Predicate<T>. However in the second example the wildcard ? doesn't mean the same thing in both places; the two wildcards are independent.Stevens Miller wrote:if both have the same erasure?
"Il y a peu de choses qui me soient impossibles..."
"Il y a peu de choses qui me soient impossibles..."
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Jeanne Boyarsky wrote:??? I don't know how that can be either.
Core Java wrote:You cannot use type variables in expression such as new T(...) new T[...], or T.class. For example, the following Pair<T> constructor is illegal:
Type erasure would change T to Object, and surely you don’t want to call new Object(). As a workaround, you can construct generic objects through reflection, by calling the Class.newInstance method.
Unfortunately, the details are a bit complex. You cannot call
The expression T.class is not legal. Instead, you must design the API so that you are handed a Class object, like this:
This method could be called as follows:
Note that the Class class is itself generic. For example, String.class is an instance (indeed, the sole instance) of Class<String>. Therefore, the makePair method can infer the type of the pair that it is making.
"Il y a peu de choses qui me soient impossibles..."
"Il y a peu de choses qui me soient impossibles..."
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Jeanne Boyarsky wrote:Interesting and definitely cow worthy!
"Il y a peu de choses qui me soient impossibles..."
The NetBeans IDE wrote:
method classy in class Main cannot be applied to given types;
required: Class<T>, Class<T>
found: Class<Square>, Class<Round>
reason: inferred type does not conform to equality constraint(s)
inferred: Round
equality constraint(s): Round,Square
where T is a type variable
T extends Object declared in method <T>classy(Class<T>,Class<T>)
"Il y a peu de choses qui me soient impossibles..."
"Il y a peu de choses qui me soient impossibles..."
"Il y a peu de choses qui me soient impossibles..."
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |