Is there something like extension functions for Java or other popular languages?

In Kotlin, we have a great feature like Extension. Where even a new custom method can be added to the superclass whose object was created. Access to this method can be obtained by an object created in the code.

My question is basically split into two.

  • Was there any concept of this function in Java or other popular programming languages?

  • If the previous answer is no , are there any ways to work around solutions in Java or other languages?

+4
source share
4 answers

java , Lombok , @ExtensionMethod api . - :

https://projectlombok.org/features/experimental/ExtensionMethod

, , ...

+4

Swift . .

, Kotlin , , Java , , , java, - .

0

. . , python.

0

We have an extension in C # and D, and we have implicit methods in Scala that can mimic such a language function.

In Ruby, you can even define methods for an object without affecting any other objects of the same type.

0
source

Source: https://habr.com/ru/post/1694640/


All Articles