2

Ive the next question and when trying to post appears the message "Your post appears to contain code that is not properly formatted as code" . I dont know which part is missing the "formatting code" advice.. some help is very appreciated:


Im reading the incredible book “a programmer's guide to java scjp certification” for jdk6 and theres a section about generic overriding. On it is described subsignature and override-equivalent and describes some examples of override-equivalent that I quote:

>Given the following three generic method declarations in a class:
>
>`static  void merge (MyStack s1, MyStack s2) { /*...*/ }`
>
>`static  void merge (MyStack s1, MyStack s2) { /*...*/ }`
>
>`static  void merge (MyStack s1, MyStack s2) { /*...*/ }`
>
>After erasure, the signature of all three methods is: `merge(MyStack, MyStack)`
>i.e., the signatures of the methods are override-equivalent, hence these methods
>are not overloaded. 

Im not totally agree that these methods are override-equivalent , in fact i think the methods have an “erasure clash” but none is subsignature of the other one… possibly im wrong so i want some light on this. 

The definitions of subsignature makes me think that they arent subsignatures between them.

In JSL 6 #8.4.2 Method Signature ([http://docs.oracle.com/javase/specs/jls/se6/html/classes.html#8.4.2][1])

>Two methods have the same signature if they have the same name and argument types.
>Two method or constructor declarations M and N have the same argument types if all of the following conditions hold:
>
>- They have the same number of formal parameters (possibly zero)
>
>- They have the same number of type parameters (possibly zero)
>
>- Let `` be the formal type parameters of M and let `` be the formal type parameters of N. After renaming each occurrence of a Bi in N's type to Ai the bounds of corresponding type variables and the argument types of M and N are the same.
>
>The signature of a method m1 is a subsignature of the signature of a method m2 if either
>m2 has the same signature as m1, or
>the signature of m1 is the same as the erasure of the signature of m2.
>
>`...`
>Two method signatures m1 and m2 are override-equivalent iff either m1 is a subsignature of m2 or m2 is a subsignature of m1.   

In JSL 8 # 8.4.2. Method Signature ([http://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.4.2][2])

>Two methods or constructors, M and N, have the same signature if they have the same name, the same type parameters (if any) (§8.4.4), and, after adapting the formal parameter types of N to the the type parameters of M, the same formal parameter types.
>
>The signature of a method m1 is a subsignature of the signature of a method m2 if either:
>
> - m2 has the same signature as m1, or
>
> - the signature of m1 is the same as the erasure of the signature of m2.
>
>Two method signatures m1 and m2 are override-equivalent iff either m1 is a subsignature of m2 or m2 is a subsignature of m1.


  [1]: http://docs.oracle.com/javase/specs/jls/se6/html/classes.html#8.4.2
  [2]: http://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.4.2

4
  • When I paste this in the editor (on Stack Overflow), it doesn't give any errors regarding the code...
    – nicael
    Jul 3, 2015 at 18:03
  • 3
    Oh @nicael, don't do that again. Editing the text here is like editing the code on Stack Overflow. By adding four spaces to every line you have changed the meaning of the question.
    – ChrisF Mod
    Jul 3, 2015 at 18:12
  • @Chris You change the true meaning of some lines by rolling back my edit, though. Look at - Let `` be the formal type..., for example, click "edit" and see how it should look.
    – nicael
    Jul 3, 2015 at 18:15
  • 2
    @nicael I can't explain that, but I nearly posted an incorrect answer based on what you edited the post to be.
    – ChrisF Mod
    Jul 3, 2015 at 18:17

0

Browse other questions tagged .