I went to it today and the only thing I can think of is that it is a bug in the Java compiler, The code is compiled, but definitely seems to be incorrect (since the test method has a different signature in the child but the parent is overridden) and the class cast throws exception at runtime.
Public Interface Test Interface & lt; T & gt; {Public listing & lt; String & gt; How to check (); // & lt; - List & lt; String & gt; } Applies the public class testclass test interface {@ Override Public List & lt; Integer & gt; TestMethod () {// & lt; - List & lt; Integer & gt; Overriding list & lt; String & gt; !! Return collection Singleton List (1); }} and using the above structure:
Public Zero Test () {Test Interface & lt; Boolean & gt; Test = new test class (); & Lt; String & gt; Wire = test.testMethod (); For (string s: strings) {System.out.println (s); }} It's all right, but obviously, if you run it, then obviously the class will leave the exception.
If you select & lt; T & gt; Remove TestInterface from , or fill in the line T , then test class tools test interface & lt; T & gt; the code will no longer compile, which makes sense. On the compilation of testmethod , IMO & lt; T & gt; should not have any effect because it does not play any part in that method. Probably & lt; T & gt; To add to the test interface, the compiler is being created due to the method signing type, although T does not participate in those methods ...? Do anyone know what's going on here?
If you use the normal range raw type, all contains the common type parameter compiler , So it does not give you any warning / error during compiling. To wit. Public class test class has implemented the test interface ... Degrades the code effectively
Public Interface TestInterface {Public List Testing Method (); } Applies the public class testclass test interface {@ Override Public List Test Meth (collections) .Singlington List (1); }} which actually compile exactly.
Similar problem was posted a couple of weeks ago, stating that it is not a compiler bug, rather a deliberate design decision for backward compatibility.
Comments
Post a Comment