[Solved] Are there decorators in java or c# like python functools decorators i.e. @wraps


There isn’t an equivalent to decorators in Java.

As I understand it, decorators in Python are essentially syntactic sugar for method transformations. For example (from PEP 318):

def foo(cls):
    pass

foo = synchronized(lock)(foo)
foo = classmethod(foo)

becomes this:

@classmethod
@synchronized(lock)
def foo(cls):
    pass

That kind of thing won’t work in Java because Java methods are not first class objects, and the binding between a Java method and a method name is not mutable.

You might be able to do some things that you can do with Python decorators using annotation-driven code Java source code or bytecode rewriting, etcetera. However decorators implemented that way should be considered part of the Java language. (Just like Lombok-ified Java isn’t real Java.)

solved Are there decorators in java or c# like python functools decorators i.e. @wraps