Skip to content

Automatically ignore static fields #464

@aemeryjsa

Description

@aemeryjsa

Currently, static fields in the model contribute to the model definition.

For example, the following class contains the static, final field MAX_ROOMS.

public class House extends RealmObject {
    private int roomCount;
    public static final int MAX_ROOMS = 10;
}

Attempting to compile results in the the following compile-time exception:
Error:The fields of the model must be private

I don't think static fields should contribute to the model definition. They belong to the class, not the instance, so it doesn't make sense for them to become a model property. They should be implicitly ignored.

Adding the Ignore annotation to the field allows it to compile:

public class House extends RealmObject {
    private int roomCount;
    @Ignore public static final int MAX_ROOMS = 10;
}

Also, the error message could be improved by mentioning what field in what class caused the exception.

Realm: 0.70.1
Android Studio: 0.8.11
OS: Window 8

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions