Coder Social home page Coder Social logo

generic-enums's People

Contributors

cloudpay-simon avatar cmoine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

cloudpay-simon

generic-enums's Issues

Support generics inside variables

Hi!
Very cool feature I must say!

I'm trying to achieve something but I can seem to make it work.
This is my example:

@GenericEnum
public enum Test implements ActionFactory<@GenericEnumParam Object> {

    FEATURE_FLAGS(AActionClass.class, a -> new AActionClass()),
    NOT_FEATURE_FLAGS(BActionClass.class, b -> new BActionClass());


    Test(Class<? extends ActionClass> actionClass, ActionFactory<@GenericEnumParam Object> constructor) {
        this.constructor = constructor;
    }

    private final ActionFactory<@GenericEnumParam Object> constructor;


    @Override
    public @GenericEnumParam Object getAction(String s) {
        return constructor.getAction(s);
    }
}

This is the ActionFactory class:

interface ActionFactory<T> {
    T getAction(String input);
}


public class ActionClass {

    public void method() {
        System.out.println("method");
    }
}

public class AActionClass extends ActionClass {

    public void a() {
        System.out.println("A");
    }
}


public class BActionClass extends ActionClass {
    public void b() {
        System.out.println("A");
    }
}

After compile it creates TextExt with some errors:

    public static final TestExt<AActionClass> FEATURE_FLAGS=new TestExt<AActionClass>(AActionClass.class, (a)->new AActionClass(), "FEATURE_FLAGS", 0);
    public static final TestExt<BActionClass> NOT_FEATURE_FLAGS=new TestExt<BActionClass>(BActionClass.class, (b)->new BActionClass(), "NOT_FEATURE_FLAGS", 1);
    private final String __enum_name__;
    private final int __ordinal__;
    private final ActionFactory<@GenericEnumParam() Object> constructor;

    private TestExt(Class<? extends ActionClass> actionClass, ActionFactory<@GenericEnumParam() Object> constructor, String __enum_name__, int __ordinal__) {
        this.constructor = constructor;
        this.__enum_name__=__enum_name__;
        this.__ordinal__=__ordinal__;
    }

    public T getAction(String s)  {
        return constructor.getAction(s);
    }

The constructor variable is ActionFactory<@GenericEnumParam() Object> instead of ActionFactory<T>

  • in the TextExt constructor method
    private TestExt(Class<? extends ActionClass> actionClass, ActionFactory<@GenericEnumParam() Object>

Am I missing anything ? is this something I can achieve with current implementation or it's a new feature need to develop ?

Thanks!!

Support enums in outer classes

Hi Christophe,

Great project. Would it be possible to add support for enums inside classes?

For example:

class MyOuterClass {
  public enum InnerEnum implements MyInterface<T> {
    ONE(String.class), 
    TWO(Date.class);
    ...
  }
}

I have a branch with this working, it needs some tidying up which I should be able to do early next week. If I do that would you consider merging it?

Cheers,
Simon

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.