Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes Simple generics - error in code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Simple generics - error in code" Watch "Simple generics - error in code" New topic
Author

Simple generics - error in code

Rahul Sudip Bose
Ranch Hand

Joined: Jan 21, 2011
Posts: 637

What is the mistake in this code ? (details of the error given after the program)



error :


SCJP 6. Learning more now.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3995
    
  18

The error message says exactly what's wrong. Take some time to read it.


The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20080
    
  30

nums is an array of X. That can be Double, but also Float, Integer, Long, etc. All you know is that whatever X really is, its base class is Number. So use Number in the loop. It has the doubleValue() method as well.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rahul Sudip Bose
Ranch Hand

Joined: Jan 21, 2011
Posts: 637

Thanks to all for helping me !
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20080
    
  30

You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple generics - error in code
 
It's not a secret anymore!