Can Getters/Setters for Booleans be handled like primitive booleans, if they already have an "is"-prefix?

1,193 views
Skip to first unread message

Simon

unread,
May 27, 2021, 8:59:30 AM5/27/21
to Project Lombok
I recently posted a stackoverflow question about how to handle Boolean Getter/Setter like primitive booleans, because all our Booleans are prefixed with "is" and Lombok handels boolean and Boolean differently.


Thanks for your advice which magic annotations I have to use to achieve this? :)

Reinier Zwitserloot

unread,
Jun 18, 2021, 1:10:49 PM6/18/21
to Project Lombok
A long time ago in a galaxy far far away, we did exactly what you describe: `Boolean` types were defaulted to an `is` prefix.

But, we got a ton of bug reports that this breaks beanspec, so we did a tiny backwards break (this was back when lombok had far fewer users, so I forgive myself a little bit for it) and changed the behaviour.

Since then, bug reports about us breaking beanspec have only increased, but it's mostly about our behaviour on capitalizing fields name `ABfoo` (2 initial capitals, then lowercase letters). The major problem is that beanspec is not really a thing; there are multiple conflicting documents, and many different behaviours in the community that don't follow any of them but are written by people who think they are adhering to it.

At any rate, all the conflicting specs all agree that capital-B Booleans should have a get and not an is prefix.

We won't be changing this behaviour and I don't think it's a good idea to add some esoteric lombok.config or `@Getter` switch to change it.

I'd go to the root of the issue and figure out why you have method that return a capital-B Boolean. That's almost always a code smell. It's java, not SQL: tri-state booleans are unexpected, undesired, and don't interact well with any other java code.

Thorsten Glaser

unread,
Jun 21, 2021, 11:45:40 AM6/21/21
to Project Lombok
On Fri, 18 Jun 2021, Reinier Zwitserloot wrote:

> A long time ago in a galaxy far far away, we did exactly what you describe:
[…]

Thanks for the background info!

> I'd go to the root of the issue and figure out why you have method that
> return a capital-B Boolean. That's almost always a code smell. It's java,

Huh. So indeed.

Unfortunately, BiFunction<Integer, Integer, boolean> does not work (but
the code I just tested that with explodes if the passed function returns
null so I indeed really want a lowercase boolean). Is there anything I
can use?

bye,
//mirabilos
--
Infrastrukturexperte • tarent solutions GmbH
Am Dickobskreuz 10, D-53121 Bonn • http://www.tarent.de/
Telephon +49 228 54881-393 • Fax: +49 228 54881-235
HRB AG Bonn 5168 • USt-ID (VAT): DE122264941
Geschäftsführer: Dr. Stefan Barth, Kai Ebenrett, Boris Esser, Alexander Steeg

*************************************************

Mit dem tarent-Newsletter nichts mehr verpassen: www.tarent.de/newsletter

*************************************************

JayC667

unread,
Jun 21, 2021, 12:08:37 PM6/21/21
to Project Lombok
If it's just about the BiFunction, why not introduce you own @FunctionalInterface that returns a boolean, and maybe even takes primitives as parameters in place of generic reference types?

Something along the lines of

@FunctionalInterface
public interface MyFunctionalInterface {
    boolean haveSomeFun(int param1, int param2);
}


... unless of course the BiFunction is ultimately required by some other code you cannot change...
But the you still have to possibility to use something in between, that converts Boolean to boolean with default values, thus enabling Lombok to create the getters you want?

Thorsten Glaser

unread,
Jun 21, 2021, 2:19:41 PM6/21/21
to Project Lombok
On Mon, 21 Jun 2021, JayC667 wrote:

> If it's just about the BiFunction, why not introduce you own
> @FunctionalInterface that returns a boolean, and maybe even takes
> primitives as parameters in place of generic reference types?

Oh, good point… I wasn’t aware I could do that… it’s just used so
a function reference or lambda can be passed.

Thanks,

Marco Servetto

unread,
Jun 21, 2021, 10:56:50 PM6/21/21
to project...@googlegroups.com
I think you just want to use a BiPredicate :-)
> --
> You received this message because you are subscribed to the Google Groups "Project Lombok" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to project-lombo...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/project-lombok/af609a2b-733f-18ab-6bc8-bcf32e5a4132%40tarent.de.
Reply all
Reply to author
Forward
0 new messages