Overriding with subclass as a parameter and generics: where is it in Java Lang Spec? -


I have run a Java code similar to the following:

  Public Interface BaseArg {} Public Class DeriveArg BaseArg {} Public Abstract Class Base Apply & amp; One base order & gt; {A Arg; Zero doIt () {printArg (arg); } Zero printAg (AA) {System.out.println ("base:" + A); }} Public category derivative base & lt; DerivedArg & gt; {Void printArg (DerivedArg a) {System.out.println ("Excluded:" + A); } Public static zero main (string [] args) {derived d = new derived (); D.arg = New DerivedArg (); D.doIt (); }}  

(Feel free to split it into files and run it).

This code ends with the implementation of printArg derived. I realize that this is just a logical thing. However, if I manually execute "erasure" on the generic base, replacing all events in A with BaseEge, overriding breaks. Now I get the version of the print base.

It looks like "extinction" is not total - in some way it is not similar to printArg (AA) printarge (Bassierge A). I can not find any basis for this about the language ...

What about language? It's not really important, but it bugs me :).

Please note that the derivative method is The question is, that your Looking at deleted signatures, there is no override-equivalent.

When the range is prepared, then the compiler actually exits two methods: method printArg (DerivedArg), and a synthetic method printArg (BaseArg) which overrides the superclass method, even so That a virtual machine can understand the unknowing of type parameters, and explain the representatives of printArg (DerivedArg). You can throw an exception in printArt (DerivedArg) by calling it on the context of base basis and checking the stack trace:

  Exception in thread "main" java.lang Derive.printArg ( Test.java:1) at Runtime Expansion on Derive.printArg (Test.java:28) & lt; & Lt; Test. Artificial on Base. Doti (Test. Java 14) on Main (Test.Java.39).  

To find it in the specificity of the Java language, I was remembered before, because it is not as one can expect, where it has been specified that Overriding or sub-relation relations are discussed, but in "member and quantized type of connectors", which states that the formal type of super-class parameters are actually for the actual type parameter override equivalent Subclass before Anc.

That is, override conformance is not affected by extinction, contrary to popular belief.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -