• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

How Do I Get an Object of a parameterized Class?

 
Ranch Hand
Posts: 244
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to write a Java program that reads records from disk, sorts them, and then writes them in sorted order back to disk, and does it (hopefully) very quickly. I don't care what type the records are, as long as they extend {Comparable}, and I don't care how they get read from disk or written back to disk, as long as the I/O class extends my interface {InputOutput} defined like so:

So I wrote my code like follows:

When I try to compile this I get told:

HorseFly.java:40: error: unexpected type
IO InpOutp = new IO();
^
required: class
found: type parameter IO
where IO,EL are type-variables:
IO extends InputOutput<EL> declared in class HorseFly
EL extends Comparable<EL> declared in class HorseFly

I need to create an Input/Output object somehow, so I can read my {EL} elements from disk and write sorted {EL} elements back to disk. If I can't call a constructor to get such an object, how can I get it?

Kevin S
 
Author
Posts: 213
10
Scala IntelliJ IDE Netbeans IDE Python Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The generic types in Java are compile time features only, used for consistency checking. Your problem, I believe relates to "non reifiable types".

This will probably help you understand this. http://docs.oracle.com/javase/tutorial/extra/generics/fineprint.html

HTH

 
Saloon Keeper
Posts: 14490
325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry to be so blunt, but this code is really messy. Your variables are unreadable and your methods names don't seem to match their purposes. Instantiate your class with readers and writers. Decouple responsibilities:


 
Hey, sticks and stones baby. And maybe a wee mention of my stuff:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic