添加方法org.w3c.dom.Node中 [英] add methods to org.w3c.dom.Node
问题描述
我尝试添加自定义的方法Node类,但最终创建一个变量保存一个节点对象的新类。
因此问题。是它甚至可能吗?
我这样做:
公共类旅行实现org.w3c.dom.Node中的{
[...生成的方法...]
公共字符串myMethod的(){
返回;
}
}
但我获得了大量的错误,所以我结束了做这个
公共类旅行{
私人节点了mnode;
公共无效之旅(节点tripNode){
this.mNode = tripNode;
}
公共字符串myMethod的(){
返回;
}
}
org.w3c.dom.Node中是一个接口,因此你贴code将无法工作。
您不想开始尝试实现自己的DOM,所以我建议你认为一个不同的方法。什么是你想干什么?
您也许可以利用get和<一个href=\"http://download.oracle.com/javase/6/docs/api/org/w3c/dom/Node.html#setUserData%28java.lang.String,%20java.lang.Object,%20org.w3c.dom.UserDataHandler%29\"相对=nofollow> setUserData来来达成你的目标。
I tried adding a custom method to the Node class but ended up creating a new class that holds a node object in a variable.
so the question is. is it even possible?
I did this:
public class Trip implements org.w3c.dom.Node {
[...generated methods...]
public String myMethod(){
return "";
}
}
but I was getting lots of errors so I ended up doing this
public class Trip {
private Node mNode;
public void Trip(Node tripNode){
this.mNode = tripNode;
}
public String myMethod(){
return "";
}
}
org.w3c.dom.Node is an interface, therefore your posted code won't work.
You don't want to start trying to implement your own DOM, so I suggest you think of a different approach. What is it you want to do?
You might be able to make use of get and setUserData to accomplish your goal.
这篇关于添加方法org.w3c.dom.Node中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!