overriding and overloading in java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #16
    Originally posted by madhoriya22
    Hi,
    My compiler version is 1.5.0_04.
    Note : I am not trying to prove anything wrong. Just trying to resolve my confusion :(
    Are you sure? the command is

    Code:
    javac -version
    It will show some usage info but will contain the javac version as the first line.
    If you look at those errors you should see that your compiler doesn't even support autoboxing

    Comment

    • Nepomuk
      Recognized Expert Specialist
      • Aug 2007
      • 3111

      #17
      Hm, it works fine with javac 1.5.0_06 under Windows, but with version 1.4.2 under Linux it gives the message
      Code:
      Exception in thread "main" java.lang.Error: Unresolved compilation problem:
           Type mismatch: cannot convert from int to Number
      
        at Foo.print(Bar.java:5)
        at Bar.main(Bar.java:18)
      How very strange!

      Greetings,
      Nepomuk
      Attached Files
      Last edited by Nepomuk; Sep 7 '07, 09:53 AM. Reason: Added the exact code I've used (just rename Bar.txt to Bar.java)

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #18
        Originally posted by nepomuk
        Hm, it works fine with javac 1.5.0_06 under Windows, but with version 1.4.2 under Linux it gives the message
        Code:
        Exception in thread "main" java.lang.Error: Unresolved compilation problem:
             Type mismatch: cannot convert from int to Number
        
          at Foo.print(Bar.java:5)
          at Bar.main(Bar.java:18)
        How very strange!

        Greetings,
        Nepomuk
        Autoboxing was one of the new features in 1.5.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #19
          Originally posted by r035198x
          Autoboxing was one of the new features in 1.5.
          If I remember well covariant return types were not allowed in Java 1.4.2 and before;
          if I'm right the problem is not autoboxing, it's the covariancy of return types.

          kind regards,

          Jos

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #20
            Originally posted by JosAH
            If I remember well covariant return types were not allowed in Java 1.4.2 and before;
            if I'm right the problem is not autoboxing, it's the covariancy of return types.

            kind regards,

            Jos
            You're right. Covariant return types were added in 1.5 together with generics. The problem should be both covariant return types and autoboxing in my example because I'm returning ints where Number and Integer are expected.

            Comment

            • madhoriya22
              Contributor
              • Jul 2007
              • 251

              #21
              Originally posted by r035198x
              Are you sure? the command is

              Code:
              javac -version
              It will show some usage info but will contain the javac version as the first line.
              If you look at those errors you should see that your compiler doesn't even support autoboxing
              I run the command
              Code:
               
              java -version
              and it is showing this ..
              Code:
               
              java version "1.5.0_09"
              Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_09-b03)
              Java HotSpot(TM) Client VM (build 1.5.0_09-b03, mixed mode, sharing)
              I know about generics and autoboxing (Although I never used these features). Then how come my compiler is not supporting these feartures.

              Sorry I didn't check last posts of u people. Now I get it :)
              Last edited by madhoriya22; Sep 7 '07, 11:34 AM. Reason: more details

              Comment

              Working...