• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

JLS Types, Values, Variables - Error?

 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to understand what this code is intended to demonstrate.

Taken from pg 50 of the JLS, third edition.

The problem is that the code does not compile. The indentation is wrong, there's an extra closing curly brace, and there is no enclosing type.


[ July 20, 2006: Message edited by: Garrett Smith ]
 
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm guessing that what should be happening is a compile error on the private access method, however I am also getting an error on the default access:Note that I made significant changes from their discussion code to get this far, so it is quite probable that I have deviated from what they were intending to demonstrate. This is probably a "wood for the trees" issue, but I am not seeing why the default access method is failing.

As for what this is intended to show, it is all tied up in showing what is accessible in the test() method, which has an parameter of type T which is itself defined as extending C and implementing I:So the author was intending to show what was inherited from where, and that standard access control rules apply (of course that leads me back to the question of "why didnt mCDefault() work given that it is in the same (default) package as the CT class and the I interface"?

Regards, Andrew
 
Andrew Monkhouse
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It should also be noted that the fact that class CT extends C and implements I is a red herring - it has nothing to do with the code under discussion, and may distract you from what is really important.

The following code works (or fails to work!) in exactly the same way:Regards, Andrew
 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So type T is defined right before the method invocation in which it is used.



I tried this by making CT not implement mI, but that would not compile.

This, however, compiles and runs.
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Garrett Smith:
I'm trying to understand what this code is intended to demonstrate.

Taken from pg 50 of the JLS, third edition.

The problem is that the code does not compile. The indentation is wrong, there's an extra closing curly brace, and there is no enclosing type.



[ July 20, 2006: Message edited by: Garrett Smith ]



It is intended to demonstrate what members the type variable T has: the intersection of C & I. Unfortunately the example is horribly broken as you have found out. Were the generic method moved to a different class declaration, and had CT implemented mI() you would see what they intended.
 
Andrew Monkhouse
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Garrett Smith:
This, however, compiles and runs.

I am still getting an error with that code - still on the mCDefault() method:Which version of the JDK are you using?

Regards, Andrew
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps your host has more than one unnamed package.
 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using JRockit.

H:\>java -version
java version "1.5.0_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)
BEA JRockit(R) (build R26.0.0-189-53463-1.5.0_04-20051122-2041-win-ia32, )

H:\>
[ July 21, 2006: Message edited by: Garrett Smith ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic