Kotlin style Infix methods to Java by Lombok

Skip to first unread message

Artur Zuravljov

Jun 18, 2021, 12:51:32 PM6/18/21
to Project Lombok

Can you please implement infix methods based on static method call to have Kotlin feature of infix method for any Class, if it is possible.

Here is example i expect to have 

@Infix(methodAddTo = List.class)
public static boolean addIfNotExists(List list, String str) {
// list is the actual instance we call method from.
return true;
return false;

public static void main (String [] args) {
ArrayList<String> arrayList = new ArrayList<String>();

boolean result1 = arrayList.addIfNotExists("Hello World!");
boolean result2 = arrayList.addIfNotExists("Hello World!");

LinkedList<String> linkedList = new LinkedList<String>();

boolean result3 = linkedList.addIfNotExists("Hello World!");
boolean result4 = linkedList.addIfNotExists("Hello World!");

Thank you!
Have a good day!


Jun 18, 2021, 1:03:29 PM6/18/21
to Project Lombok
This seems to be similar to extension methods (https://projectlombok.org/features/experimental/ExtensionMethod)

Reinier Zwitserloot

Jun 18, 2021, 1:03:32 PM6/18/21
to Project Lombok
It's already in lombok has been for years :)

Artur Zuravljov

Jun 18, 2021, 2:14:41 PM6/18/21
to project...@googlegroups.com
Yes. It seems so. Thank you.
Have a good day. 

пт, 18 июн. 2021 г., 20:03 'Rawi' via Project Lombok <project...@googlegroups.com>:
You received this message because you are subscribed to a topic in the Google Groups "Project Lombok" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/project-lombok/5_Fe3LWMXdk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to project-lombo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/project-lombok/e079eb56-3d98-4729-b12a-b0c0654ad289n%40googlegroups.com.
Reply all
Reply to author
0 new messages