• 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

Generic parameter constructors

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider the foll. code-

public class Y {

public <Z> Y(X x) {
}

public static void main (String... args) {

}

}

I do not understand why the code above compiles. The parameter list of the constructor contains a variable of type X, but X is not defined anywhere!, why is there no compiler error? If I change X to some other name, I get the standard compiler error viz. 'cannot find symbol'.

Please explain.

Regards
Percy
 
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Percy, your code does not compile. Check if you have a class named X in your classpath.

Your code would compile if you change it like this:

 
Ranch Hand
Posts: 37
IntelliJ IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just follow codes can be compiled
class Y {

public <Z> Y(Z x) {
}

public static void main(String... args) {

}
}
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do agree with Serigo. You would have a class named X in your local directory
or in the directory whose path comes in the classpath.

A nice way what you intend to do:




Thanks,
[ May 27, 2007: Message edited by: Chandra Bhatt ]
 
Who among you feels worthy enough to be my best friend? Test 1 is to read this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic