Java equivalent to C# extension methods

Fabio Milheiro picture Fabio Milheiro · Dec 5, 2010 · Viewed 100k times · Source

I am looking to implement a functionality in a list of object as I would in C# using an extension method.

Something like this:

List<DataObject> list;
// ... List initialization.
list.getData(id);

How do I do that in Java?

Answer

SLaks picture SLaks · Dec 5, 2010

Java does not support extension methods.

Instead, you can make a regular static method, or write your own class.