Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to return enumerate in method

Tags:

java

Product.java

public interface Product {
    /**
     * use this interface for creating your own enumerate of products
     */
    public static interface Category {
        enum MyCategory {vegetable, fruit, chocolate};   // i create my own enumerate

    }

}

in my MyProduct.java i need implement getCategory() method

public class MyProduct implements Product {

    @Override
    public Category getCategory() {
     // ???
    }

}

but i don't know how to access enumerate from interface Category and still returning variable of Category. Con you help me please. Sorry for bad description of my problem, but I hope you understand what I need :)

like image 943
Michal Loksik Avatar asked Aug 15 '26 19:08

Michal Loksik


1 Answers

The full name of the enum would be Product.Category.MyCategory (prefixed by the package name if any). Within Product, you can write that as just Category.MyCategory.

like image 61
T.J. Crowder Avatar answered Aug 17 '26 09:08

T.J. Crowder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!