wood burning stoves 2.0*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 19654
    
  18

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
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: 19654
    
  18

You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with Generic
 
Similar Threads
Implementing interface with list of generics
How to correctly use a fixed size thread pool?
Not sure whether to override or overload methods in interface
Try to understando generic methods
Generics in Interfaces