This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Problem with Generic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem with Generic" Watch "Problem with Generic" New topic
Author

Problem with Generic

Alex Kruglov
Greenhorn

Joined: May 06, 2008
Posts: 8
Hi, everyone!

I have a following code:


When I'm trying to implement this interfaces, for example this way:

I'm getting an error at line 21: type parameter BigDecimalResult is not within its bounds

Does anyone know what could be the problem?

Thanks in advance!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20077
    
  30

The problem is that Task's generic type is <T extends TaskResult<T>>. BigDecimalResult does not implement TaskResult<BigDecimalResult> but TaskResult<BigDecimal>. If you change the declaration to "interface Task<T extends TaskResult<?>>" it will compile. Another option is to use two generic types:
This does make it messy, and you only need it if you need the T of TaskResult.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Alex Kruglov
Greenhorn

Joined: May 06, 2008
Posts: 8
Thanks, Rob!
It's what I needed to know.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20077
    
  30

You're welcome.
 
Have you checked out Aspose?
 
subject: Problem with Generic
 
It's not a secret anymore!