Results 1 to 3 of 3
  1. #1
    joshk6 is offline Member
    Join Date
    Jul 2010
    Rep Power

    Default Passing Enum<T> client objects

    I am writing a utility class that does comparison of predefined properties of objects. The client of this utility passes an enum which consists of the valid names of attributes of the client which the utility class can call to get a value.


    Class Client
    public enum MyAttributes {

    public <T extends Comparable<T>> getAttribValue(MyAttributes attrib){
    switch (attribut) {
    case MyAttributes.Name:
    return this.Name;

    So then I want to define this utility class that can examine the values provided by this utility class. The available attributes that can be examined are contained in the enum defined the client and pass as a type parameter to the utility object. (Utility classes all defined by some interface
    where I can get the attribute value.)

    Class CompareEngine<T extends Enum<T>> {

    public CompareEngine(Class<T> enumType) {
    T[] enumvals;
    * enumvals = enumType.values();
    //doesn't work, enumType is a class object, no values method.


    In the line with the *, I can't figure out how to pass the enum type object so that I can call its values method within the context of this utility class.

    Any help appreciated.

  2. #2
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    San Jose, CA, USA
    Rep Power


    You could get them as an array of objects:

    Java Code:
    Object[] enumvals = enumType.getEnumConstants();
    My Hobby Project: LegacyClone

  3. #3
    joshk6 is offline Member
    Join Date
    Jul 2010
    Rep Power


    Many thanks,Mr Matt,:)

    Somehow I missed that function in the suggestion list because I was so busy looking for "values()." I turns out that

    T[] =enymType.getEnumConstants() works just fine...

Similar Threads

  1. Passing Objects
    By Java_Developer in forum New To Java
    Replies: 6
    Last Post: 10-29-2009, 02:32 PM
  2. MVC passing objects
    By simo_mon in forum New To Java
    Replies: 1
    Last Post: 07-17-2009, 07:57 AM
  3. Passing objects into constructors
    By aaronfsimons in forum New To Java
    Replies: 8
    Last Post: 04-14-2009, 01:08 PM
  4. help with passing objects between classes
    By aruna1 in forum New To Java
    Replies: 7
    Last Post: 03-22-2009, 03:41 PM
  5. passing an enum type as a parameter ??!
    By SCS17 in forum New To Java
    Replies: 11
    Last Post: 07-13-2008, 02:44 PM

Tags for this Thread

Posting Permissions

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