Using optional generics

Discussion in 'Java' started by Mize-ze, Mar 1, 2007.

  1. Mize-ze

    Mize-ze Guest

    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?
    }
    -----------------------------------------------------------------------------------------------------

    Thanks
     
    Mize-ze, Mar 1, 2007
    #1
    1. Advertising

  2. -----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<T>

    > 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.

    > }
    > -----------------------------------------------------------------------------------------------------
    >
    > Thanks


    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-----
     
    Hendrik Maryns, Mar 1, 2007
    #2
    1. Advertising

  3. Mize-ze

    Ian Wilson Guest

    Mize-ze wrote:
    > 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.
     
    Ian Wilson, Mar 1, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Willem Oosthuizen
    Replies:
    1
    Views:
    2,786
    Jonathan Bromley
    Jul 9, 2003
  2. Thomas G. Marshall

    1.5: generics warning of using Raw datatype

    Thomas G. Marshall, Aug 17, 2004, in forum: Java
    Replies:
    7
    Views:
    21,696
    knightpraetor
    Jun 11, 2011
  3. Juergen Berchtel
    Replies:
    1
    Views:
    6,010
    John C. Bollinger
    May 20, 2005
  4. Nathan Harmston

    Problem using Optional pyparsing

    Nathan Harmston, Aug 16, 2007, in forum: Python
    Replies:
    2
    Views:
    451
    Paul McGuire
    Aug 16, 2007
  5. Soul
    Replies:
    0
    Views:
    524
Loading...

Share This Page