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

Default value of 0 for field is not part of [optional] enum (java) #8247

Open
djchapm opened this issue Mar 5, 2024 · 0 comments
Open

Default value of 0 for field is not part of [optional] enum (java) #8247

djchapm opened this issue Mar 5, 2024 · 0 comments

Comments

@djchapm
Copy link

djchapm commented Mar 5, 2024

flatc version 23.5.26

Similar to #5108 but For java. flatc -j test.fbs on contents:

enum InvestorType: int
{
	customer = 67,
	foreign = 70
}

table OrderSet
{
	has_order_id:bool;
	investor_type:InvestorType;
}

Error:
test.fbs:10: 28: error: default value of 0 for field investor_type is not part of enum InvestorType.

According to #5108 there should be an implicit 'NONE' field. Also since the field is optional, I'd think hasInvestorType would return false and investorType would be null by default instead of having to set the default.

We can't specify a value '0' for various reasons, we don't want the possibility. It does work if I declare investor_type:InvestorType = null;, but isn't this what optional means? We don't have to provide =null; for any other types as far as I know, correct me if I'm wrong.

Thanks!

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

1 participant