注解 vs XML,优缺点 [英] Annotations vs XML, advantages and disadvantages

查看:31
本文介绍了注解 vs XML,优缺点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Java 新手,我正在阅读有关注释和 xml 的内容,我个人发现 xml 有很多优点,例如它可以放在应用程序之外,无需重新编译类文件即可进行更改.如果我使用注释,如果我需要进行更改,则需要转到源代码并重新编译.如果是这种情况,我们为什么要使用注解

i am new to java here, I was reading about annotations and xml, personally I find out xml has lot of advantages like it can be put outside application, changes can be made without recompiling class files. If i use annotations if I need to make changes need to go to source code and recompiling should be done. If this is the case why should we use annotations

推荐答案

注解的优点:

1) 所有信息都在一个文件中(不需要打开两个文件来配置给定的行为)
2)当类发生变化时,无需修改xml文件

1) All the information is in a single file (no need to open two files to configure a given behavior)
2) When the class changes, no need to modify the xml file

xml文件的优点:

1) 明确区分 POJO 及其行为
2) 当你不知道哪个 POJO 对行为负责时,更容易找到那个 POJO(搜索文件的子集而不是所有的源代码)

1) Clear separation between the POJO and its behavior
2) When you do not know which POJO is responsible for the behavior, it is easier to find that POJO (searching in a subset of files rather than all the source code)

这篇关于注解 vs XML,优缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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