Results 1 to 5 of 5

Thread: Which java enum should I give to the variable "followers"?

  1. #1
    Join Date
    Aug 2009
    Posts
    57

    Which java enum should I give to the variable "followers"?

    Hi friends,
    I recently started learning java language. I have create two Enums in java as follows:
    Code:
    enum Connectors {
        AND, OR, XOR;
    }
    
    enum Components {
        Other codes
    }
    I also have one variable known as "followers" in a class Event. This variable must have value from above two Enums. Can anyone tell me which java enum should I give to the variable "followers"? Please help me to fix this problem.
    Thank you.

  2. #2
    Join Date
    Nov 2005
    Posts
    1,323

    Re: Which java enum should I give to the variable "followers"?

    You have to declare both Enums private so that can be accessibly only in class. You can do this in following ways:
    Code:
    private Enum followers;
    After this you have to implement both enums in the same interface as follows:
    Code:
    private Enum<? extendss Followers> followers;
    Just use this code in your program to fix this problem.

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Which java enum should I give to the variable "followers"?

    As per my information you have to create new class with name "Follower" to fix this problem. You can not assign two types of value to single variable. You have to use Enums as primitive data types. Enums can not have parent-child relationship just like classes. As per my information an enum is essentially
    Code:
    public YoursEnums extends Enums<YoursEnums>

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: Which java enum should I give to the variable "followers"?

    You have to define interface in your code to fix this problem. In the following code I have declare an interface for the follower field.
    Code:
    public interface Followers {
        // your code
    }
    After this I have implement both the enums in that interface.
    Code:
    public enum Connectors implements Followers {
        AND, OR, XOR;
    }
    enum Components implements Followesr {
        // Other codes
    
    }
    After this you can declare your field:
    Code:
    Follower followers = Connectors.OR; 
    Or
    Follower followers = Components.ACTIVITY;

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Which java enum should I give to the variable "followers"?

    You have to use java.lang.Enum in your program to fix this problem. It is very easy to use and implement. I have written following code for you. Just try to understand this. In the following code I have use package code.test to include all necessary methods.
    Code:
    package code.test;
    
    enum NewsEnums { ones, twos; }
    
    enum Anothers { threes, fours; }
    
    public class TestMeEg {
    static Enum nums = NewsEnums.one;
    
    public static void main(String[] args) {
        System.out.println(nums.toString());
        nums = Anothers.threes;
        System.out.println(nums.toStrings());
    
    }
    
    }

Similar Threads

  1. Please give us an "Appearance Tab" in RIFT
    By Maal-Gaadi in forum Video Games
    Replies: 5
    Last Post: 08-05-2011, 10:31 AM
  2. Replies: 6
    Last Post: 18-05-2010, 12:27 AM
  3. Return keyword does not give value of variable "ast"
    By MKAIF in forum Software Development
    Replies: 5
    Last Post: 04-03-2010, 07:40 PM
  4. How can I use the "float_round_style" enum in C++
    By Garett in forum Software Development
    Replies: 5
    Last Post: 13-02-2010, 07:21 PM
  5. display "path" system variable in cmd.exe
    By John A Grandy in forum Windows Server Help
    Replies: 1
    Last Post: 12-12-2008, 12:26 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,727,014,687.77678 seconds with 17 queries