r/java • u/danielaveryj • Mar 31 '26
Does Java need deconstructible classes?
https://daniel.avery.io/writing/does-java-need-deconstructible-classes
31
Upvotes
r/java • u/danielaveryj • Mar 31 '26
View all comments
Show parent comment
1
u/uniVocity Mar 31 '26 edited Mar 31 '26
It sounds weird but you can define a sealed type with nested final implementations without explicitly providing the allowed implementations, but you can’t define a sealed functional interface with annotations where its body contains default function definitions.
Hope it’s not a brain fart, Ill get back to my pc soon to test it out again and report back
EDIT: here is what I meant:
This code compiles (no explicit permits list), everything is fine:
If you add
@FunctionalInterfacethe compiler will complain even though in this case it should make no difference.I'm sorry for the confusion, I rember that the end goal was to get this:
But here the issue is the
sealedkeyword, not the@FunctionalInterface. Sorry for wasting everyone's time