Jim
Jim

Reputation: 19572

How can I define this generic class to return this kind of generic object?

I have a generic class as follows:

class Holder<T>{  
    int type;  
    T value;  
}  

I have a class with method as follows:

class SomeClass<T> {  
T insideValue;

??? process();  

}

I need from process to return a Holder<T>. How can I do this? What do I need to change in order to work? I think that if I did:
class SomeClass<Holder<T>> { it would be the same as class Holder<T> right?

Upvotes: 1

Views: 110

Answers (2)

Avinash Singh
Avinash Singh

Reputation: 3787

You can use something like this,

Holder<T> process(){

}

Upvotes: 2

SLaks
SLaks

Reputation: 887469

Very simply:

Holder<T> process();

Closed generic types can be used just like other types (except at runtime).

Upvotes: 4

Related Questions