aspose file tools*
The moose likes Java in General and the fly likes TypeSafe Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "TypeSafe Class" Watch "TypeSafe Class" New topic
Author

TypeSafe Class

Stanley Walker
Ranch Hand

Joined: Sep 23, 2009
Posts: 87
I wanted to create a template for classes which would performing validations on data transfer objects being used. All my data transfer object would be implementing a marker interface


I have defined my template class as abstract and type safe in the fol way:



Now when i am creating a concrete implementation of the above template when i do this:




Can someone please explain the below error ?
compiler gives me an error which states: Description Resource Path Location Type
Bound mismatch: The type MYDTO is not a valid substitute for the bounded parameter <T extends IDataTransferObject> of the type ValidatorTemplate<T> MyValidator.java
and also - The type parameter MYDTO is hiding the type MYDTO


my MYDTO class is defined as:



Please explain why the above is failing. I do not udnerstand the issue. when i do the following it works:



what will be the correct implementation of ValidatorTemplate class?

Thank you for all your help
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Try this:


You're not parameterizing MyValidator, so you don't need the <MYDTO> after it. And if you did put a type parameter there, it would have to be a "variable" (not sure of the correct term in that context) like <T> rather than an actual class name, or at the very least, not the same as the actual class name you're providing in ValidatorTemplate<MYDTO>.

Please explain why the above is failing. I do not udnerstand the issue. when i do the following it works:



It works because now the type parameter T is not conflicting with the parameter bounds MYDTO. Those two tokens serve completely different and unrelated purposes. Also, you're not using <T> anywhere, so you may as well get rid of it.

Now, if you have something like

(or super MYTDO) and you used T somewhere, that might be a different story.
Stanley Walker
Ranch Hand

Joined: Sep 23, 2009
Posts: 87
Hi Jeff, thank you so much for the response. Can you also please explain the meaning of this error - The type parameter MYDTO is hiding the type MYDTO

this particular error sort of threw me off.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40038
    
  28
You have two things called MYDTO. find a copy of Java™ Puzzlers by Blcoh and Gafter; it has several pages about what hiding, obscuring etc., mean.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Stanley Walker wrote:Hi Jeff, thank you so much for the response. Can you also please explain the meaning of this error - The type parameter MYDTO is hiding the type MYDTO

this particular error sort of threw me off.


That's this part of what I said as to why the <T> version works:
Jeff wrote:It works because now the type parameter T is not conflicting with the parameter bounds MYDTO. Those two tokens serve completely different and unrelated purposes.


You're trying to have two unrelated identifiers named MYDTO in the same scope. If you do that, you'll only be able to refer to one of them in your code. (Are you sure that was an error by the way? Or was it a warning?)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: TypeSafe Class