Python Decorator与Java注解或具有Aspects的Java是否相同? [英] Is a Python Decorator the same as Java annotation, or Java with Aspects?

查看:56
本文介绍了Python Decorator与Java注解或具有Aspects的Java是否相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python装饰器是否与Java批注或诸如Spring AOP或Aspect J之类的相同或相似,或者从根本上不同?

Are Python Decorators the same or similar, or fundamentally different to Java annotations or something like Spring AOP, or Aspect J?

推荐答案

Python装饰器只是语法糖,用于将一个函数传递给另一个函数并用结果替换第一个函数:

Python decorators are just syntactic sugar for passing a function to another function and replacing the first function with the result:

@decorator
def function():
    pass

是...的语法糖

def function():
    pass
function = decorator(function)

Java注释本身仅存储元数据,您必须具有检查它们的内容以添加行为.

Java annotations by themselves just store metadata, you must have something that inspects them to add behaviour.

 

Java AOP系统是建立在Java之上的巨大事物,装饰器只是语言语法,几乎没有附加语义,您无法真正进行比较.

Java AOP systems are huge things built on top of Java, decorators are just language syntax with little to no semantics attached, you can't really compare them.

这篇关于Python Decorator与Java注解或具有Aspects的Java是否相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆