Results 1 to 5 of 5
  1. #1
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default [SOLVED] Can variable names be dynamically created?

    Is there a way to dynamically create a variable name? I was thinking on the terms of something like the following:

    Java Code:
    String myVar%n;
    and obtain variable names like myVar1, myVar2, myVar3, etc

    Thanks,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  2. #2
    Join Date
    Dec 2008
    Location
    Italy
    Posts
    79
    Rep Power
    0

    Default No possible

    No, it's no possible. I know a PHP similar feature, named variable variable names. But in Java in can't be accomplished, since the compiler must check every identifier at runtime. Neither using RTTI is helpful. But why do you need that missing feature?

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Thanks for the answer...

    I was afraid of that. Sometime ago, I thought that I needed it for a program (I can't remember the context). I think it had to do with printing the name of variables from different threads, but that can be solved by formatting the print output. But I still think that it would be a cool option.

    Thanks,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Usually when I think that I need this feature, a Map will often fit the bill, and that's because the problem isn't really concerning the variable name, which has little meaning, but more often it's tying a String to a specific object, something Maps do well.

  5. #5
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Great

    Furball... thanks... I'll give maps a look.

    Thanks,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. Vector getting re-created with each call
    By nidhirastogi in forum Advanced Java
    Replies: 6
    Last Post: 10-17-2008, 07:37 AM
  2. How to find file created date.....
    By roshithmca in forum Advanced Java
    Replies: 1
    Last Post: 02-18-2008, 09:48 AM
  3. Help, created a username and password box
    By cachi in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 04:21 AM
  4. create a tree when a new class is created
    By osval in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 08:58 PM
  5. building file and variable names from variables
    By madad2005 in forum New To Java
    Replies: 2
    Last Post: 07-18-2007, 04:47 PM

Posting Permissions

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