Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field types that have no empty constructor will fail to compile #3

Closed
mradzinski opened this issue Jan 12, 2016 · 5 comments
Closed

Comments

@mradzinski
Copy link

Try defining a field of type Long inside a @Store model. It will fail to compile due to the fact that java.lang.Long has no empty constructor

    public static java.lang.Long getTest() {
        return Iron.chest().read("test", new java.lang.Long()); // Long has no empty constructor
    }

May I recommend checking for the field type and acting accordingly? So, if String then new java.lang.String() will work, but if Long, Boolean, Byte, etc then the default value should be 0, false, etc (or just always return null, I mean, a null-check is pretty much common)

@FabianTerhorst
Copy link
Owner

Thanks for your testing. I will take a look inside this and i think giving the annotation a default value would be a good way.

@FabianTerhorst
Copy link
Owner

If no default value is provided with the annotation it should return null.

@mradzinski
Copy link
Author

Absolutely, that should do the trick

@FabianTerhorst
Copy link
Owner

compile 'io.fabianterhorst:iron-annotations:0.2'
apt 'io.fabianterhorst:iron-compiler:0.4'

public class Main {
    @DefaultObject
    @Name(value = "contributors", transaction = true, listener = true, loader = true, async = true)
    ArrayList<Contributor> contributors;

    @DefaultObject
    @Name("repos")
    ArrayList<Contributor> repos;

    @Name("my_username")
    String userName;

    @DefaultLong(120)
    Long bla;
}

@FabianTerhorst
Copy link
Owner

edit:apt 'io.fabianterhorst:iron-compiler:0.4'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants