Forums Register Login
generic program error

when 34 is passed ,then it will be converted into the Integer Object and passed to the constructor.So, when this code "u.byteValue()" ,which is in the display() method should be compiled properly,but it is throwing the error(because here 'u' is treated as a object)

Compiling 1 source file to C:\deploy\pbnm\class\build\classes
C:\deploy\pbnm\class\src\GenericClassNine.java:20: cannot find symbol
symbol : method byteValue()
location: class java.lang.Object
1 error
BUILD FAILED (total time: 0 seconds)
Not an advanced question. Moving...
It may not be the advanced question,but I want the answere,where can I get the answere

But look at it from the compiler's point of view. It has no way of knowing what class U will be.

The only thing the compiler knows for sure is that U is a subclass of Object.

So it can only let you call methods on the variable you that are defined in Object.
Are you okay? You look a little big. Maybe this tiny ad will help:
Become a Java guru with IntelliJ IDEA

This thread has been viewed 654 times.

All times above are in ranch (not your local) time.
The current ranch time is
Mar 20, 2019 05:59:51.