Using optional generics

M

Mize-ze

Hello,

I am intrested in creating a generic class which leaves the use of
generics optional.
I want to use the generics when I want and leave it out when I want,
just like java.util.Map
How can I?

Example:
------------------------------------------------------------------------------------------------------

public class foo<T>{
private T value;
}

public static void main (String argv[]){

foo<Integer> = new foo<Integer>(); // That's ok
foo = new foo(); // Can't do this now!
how can I?
}
 
H

Hendrik Maryns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mize-ze schreef:
Hello,

I am intrested in creating a generic class which leaves the use of
generics optional.
I want to use the generics when I want and leave it out when I want,
just like java.util.Map
How can I?

Example:
------------------------------------------------------------------------------------------------------

public class foo<T>{
private T value;
}

Please follow the naming conventions, especially if you post here:
public class Foo said:
public static void main (String argv[]){

foo<Integer> = new foo<Integer>(); // That's ok

Are you sure?
foo = new foo(); // Can't do this now!

Of course not, for the same reason as the line above.
how can I?

Don’t forget to give your variables names.

You’re welcome, H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFF5re8e+7xMGD3itQRAicnAJ98v6z5JwGRDa10RYDDCoGvQ8+5JACeONmK
W605eH4xu6sMHScLD9fEHPw=
=Kcx3
-----END PGP SIGNATURE-----
 
I

Ian Wilson

Mize-ze said:
Hello,

I am intrested in creating a generic class which leaves the use of
generics optional.
I want to use the generics when I want and leave it out when I want,
just like java.util.Map
How can I?

Example:
------------------------------------------------------------------------------------------------------

public class foo<T>{
private T value;
}

public static void main (String argv[]){

foo<Integer> = new foo<Integer>(); // That's ok
foo = new foo(); // Can't do this now!
how can I?
}
Your example doesn't compile so I surmise it is retyped and contains
numerous typos. I've therefore no way to know what is wrong with your
real code.

public class Foo<T> {
private T var;
public static void main(String[] args) {
Foo<Integer> foo1 = new Foo<Integer>();
Foo foo2 = new Foo();
}
}

Compiles and runs here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top