java jaxb如何工作? [英] how java jaxb works?
本文介绍了java jaxb如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对jaxb如何工作感到好奇,我有一个注释如下的类:
Just curious about how jaxb works, I have a class annotated as follows:
@XmlRootElement(name = "MyJaxb")
Class MyJaxb
{
@XmlElement
protected String str;
public void setStr(String str)
{
this.str = str;
}
}
字段str的访问修饰符受到保护,为什么是Jaxb仍然可以编组和取消编组吗?
The access modifier of field str is protected, why Jaxb can still marshall and unmarshall it?
推荐答案
它使用反射。可以使用反射API访问 protected
或 private
字段或方法(使用 setAccessible(在相应的
。字段
或方法
对象上)
It uses reflection. A protected
or private
field or method can be accessed using the reflection API (using setAccessible(true)
on the appropriate Field
or Method
object).
记住 - 公共
,受保护
和私人
是默认可见性的控件,仅此而已。他们没有(也不能)阻止使用反射进行访问。
Remember - public
, protected
and private
are controls on default visibility, nothing more. They do not (and cannot) prevent access using reflection.
这篇关于java jaxb如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文