Results 1 to 3 of 3

Thread: Problem in Enum

  1. #1
    Join Date
    Nov 2009
    Posts
    356

    Problem in Enum

    Hi everyone
    I have a problem in my java program. I have posted the code below. See if you can help me out.
    Code:
    <pre>public class FileSystem {
    private Directory _current;
    private enum Cmd {
    CD {
    String execute(String param) {
    Directory newDir = _current.getChild(param);
    ...
    }
    },
    ...
    ;
    abstract String execute(String param);
    }
    ...
    }</pre>
    Thanks in advacne

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Problem in Enum

    Hi
    I have noticed an error in your example, that is an enum is implicitly static, like an interface. I am posting you an example, just go through it.
    Code:
    public enum myCars{
        HONDA,BMW,TOYOTA
    };
    Code:
    public class Main {
        public static void main(String[] args) {
            // TODO code application logic here    
            myCars crrcar=myCars.BMW;
            System.out.println("My Current Cars : "+ myCars.BMW);
        }
    }

  3. #3
    Join Date
    Nov 2009
    Posts
    356

    Re: Problem in Enum

    Thanks for replying
    Ok, I forgot to think about that. I take it that this means that if I want to access member variables in my enums, I have to pass "this" in via the constructor.
    Code:
    Command c = UP(this);
    But what if I want to do something like the following
    Code:
    execute(String command, String argument) {
    Command c = Command.valueOf(command);
    c.execute(argument);
    }

Similar Threads

  1. What is an ENUM in Networking?
    By LajJlI in forum Networking & Security
    Replies: 7
    Last Post: 07-03-2011, 03:29 AM
  2. Java - question on enum
    By ISAIAH in forum Software Development
    Replies: 5
    Last Post: 02-03-2010, 10:50 AM
  3. How to use enum values in VB
    By $tatic in forum Software Development
    Replies: 1
    Last Post: 10-08-2009, 06:25 PM
  4. How to convert string to enum in vb.net application
    By GunFighter in forum Software Development
    Replies: 3
    Last Post: 30-07-2009, 01:12 PM
  5. Missing Enum File re HP printer
    By dayleking in forum Hardware Peripherals
    Replies: 4
    Last Post: 12-02-2009, 06:15 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,248,322.74095 seconds with 16 queries