Results 1 to 4 of 4
  1. #1
    tschaitanya is offline Member
    Join Date
    Jul 2008
    Posts
    2
    Rep Power
    0

    Default Using class type as variable

    Hi,
    Consider the following par of code
    Java Code:
    public setMapper (Class mapper_class) {
       // create a object named "mapper" of above class type
      mapper.doSomething ();
    }
    setMapper (xyz.class);
    How do i declare new object, for which class is stored as variable??

    Thanks

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: Using class type as variable

    Take a look at the Class API for useful functions: Class (Java Platform SE 6)
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    tschaitanya is offline Member
    Join Date
    Jul 2008
    Posts
    2
    Rep Power
    0

    Default Re: Using class type as variable

    sorry... using newInstance () we can do that...
    But how do I use in generics like
    Java Code:
    LinkedList <mapper_class> new_list;

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default Re: Using class type as variable

    Most of Generics is at compile time. Your usage appears to be at execution time.

Similar Threads

  1. What variable type should I use?
    By Eleeist in forum New To Java
    Replies: 18
    Last Post: 08-01-2011, 02:55 AM
  2. Print variable data type
    By BillyB in forum New To Java
    Replies: 1
    Last Post: 01-14-2011, 04:37 PM
  3. do while (variable != type)
    By Romally in forum New To Java
    Replies: 2
    Last Post: 11-15-2010, 05:29 AM
  4. Replies: 1
    Last Post: 12-09-2009, 12:57 AM
  5. [SOLVED] curiosity about String type variable
    By monir6464 in forum Advanced Java
    Replies: 1
    Last Post: 04-08-2008, 11:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •