cmoine / generic-enums Goto Github PK
View Code? Open in Web Editor NEWAttempt to implement https://openjdk.java.net/jeps/301 with annotation + processor
License: MIT License
Attempt to implement https://openjdk.java.net/jeps/301 with annotation + processor
License: MIT License
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>
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!!
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
Hi Christophe,
While working on another PR I've noticed that some files include "Copyright Google LLC". I suspect this is a copy'n'paste error as they are all pom.xml files. They also mention the Apache license.
I'd just like to clarify that this project falls under the MIT license.
You can see the affected files here: https://github.com/cmoine/generic-enums/search?q=copyright
Cheers,
Simon
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.