On Sat, Aug 23, 2008 at 6:06 AM, Matthew Toseland
<toad at amphibian.dyndns.org> wrote:
> On Friday 22 August 2008 16:25, Daniel Cheng wrote:
>> On Fri, Aug 22, 2008 at 9:28 PM, Matthew Toseland
>> <toad at amphibian.dyndns.org> wrote:
>> > On Thursday 14 August 2008 08:40, j16sdiz at freenetproject.org wrote:
>> >> Author: j16sdiz
>> >> Date: 2008-08-14 07:40:13 +0000 (Thu, 14 Aug 2008)
>> >> New Revision: 21832
>> >>
>> >> Modified:
>> >>    trunk/freenet/src/freenet/config/Config.java
>> >>    trunk/freenet/src/freenet/config/PersistentConfig.java
>> >>    trunk/freenet/src/freenet/config/SubConfig.java
>> >>    trunk/freenet/src/freenet/config/WrapperConfig.java
>> >> Log:
>> >> Generic
>> >>
>> >> Modified: trunk/freenet/src/freenet/config/SubConfig.java
>> >> ===================================================================
>> >> --- trunk/freenet/src/freenet/config/SubConfig.java   2008-08-14 07:39:51
> UTC
>> > (rev 21831)
>> >> +++ trunk/freenet/src/freenet/config/SubConfig.java   2008-08-14 07:40:13
> UTC
>> > (rev 21832)
>> >> @@ -304,15 +304,11 @@
>> >>               return prefix;
>> >>       }
>> >>
>> >> -     public int compareTo(Object o){
>> >> -             if((o == null) || !(o instanceof SubConfig)) return 0;
>> >> -             else{
>> >> -                     SubConfig second = (SubConfig) o;
>> >> -
> if(this.getPrefix().compareTo(second.getPrefix())>0)
>> >> -                             return 1;
>> >> -                     else
>> >> -                             return -1;
>> >> -             }
>> >> +     public int compareTo(SubConfig second) {
>> >> +             if (this.getPrefix().compareTo(second.getPrefix()) > 0)
>> >> +                     return 1;
>> >> +             else
>> >> +                     return -1;
>> >>       }
>> >
>> > Why doesn't this break Comparable ?
>> >
>>
>> Comparable<T>  gives  declarle  public int compareTo(T obj).
>> Java generic are just compile-time hints, the T is Object at bytecode level.
>
> So does the JVM synthesise a compareTo(Object) which passes along if the type
> matches? Or that it's just a completely separate mechanism?
>

It does not synthesise compareTo(Object), because <T> compareTo(T)
*is* compareTo(Object).

Java generic are just compiler hints (which give some warning/error
message, and adding type casting automatically), the underlying
bytecode is compareTo(Object) .

Reply via email to