File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Generics with methods for specific types Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Generics with methods for specific types" Watch "Generics with methods for specific types" New topic

Generics with methods for specific types

Chinababu Illa

Joined: Jun 04, 2008
Posts: 23
Hi All,

I have a class and another class

I need a method to retrieve some of the properties of XType and those properties are not available in BaseType. So that this method is not generic for both the types and is specific only to XType. This is the only method which is specific to XType, and rest all are generic methods, which convinced me to have generic class.
Is there any way, such that I can make this method visible only for the and not visible for the

R. Jain
Ranch Hand

Joined: Aug 11, 2012
Posts: 375

Why do you need a different class(Format) at all to do what you need??
You can simply have the methods(which you are calling generic) in your BaseType class and
the methods which are specific to XType will be in that class only..

The problem what you are stating is of Basic Inheritance and Dynamic Binding, rather than of Generics..
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46348
Your question is confusing, which suggests to me your inheritance design is confusing, too. I suspect the best thing to do is go back and look at the hierarchy (as RJ has already suggested) and consider whether XType extends BaseType is the best inheritance to use.
I agree. Here's the link:
subject: Generics with methods for specific types
It's not a secret anymore!