小编Thi*_*ers的帖子

如何为不同的父节点选择具有相同名称的所有节点?

假设我有以下xml:

<root>
  <person>
    <name>John</name>
  </person>
  <children>
    <person>
      <name>Jack</name>
    </person>
  </children>
</root>
Run Code Online (Sandbox Code Playgroud)

是否可以同时选择这两个人?假设我不知道另一个人在儿童标签中,他们可能很容易在配偶标签或完全不同的东西,可能在另一个孩子.我知道我需要的所有人都在根标签中(不一定是文档根目录).

xml xslt xpath

4
推荐指数
1
解决办法
1万
查看次数

为什么我不能使用实现接口的枚举列表调用方法?

我试图调用一个方法,它接受一个Enle列表(实现接口)的接口列表.这给出了以下编译错误:

The method method(List<Interface>) in the type Class is not applicable for the arguments (List<Enum>)
Run Code Online (Sandbox Code Playgroud)

这是界面:

public interface Interface {
}
Run Code Online (Sandbox Code Playgroud)

这是实现接口的枚举:

public enum Enum implements Interface {
}
Run Code Online (Sandbox Code Playgroud)

这是调用类:

import java.util.ArrayList;
import java.util.List;

public class Class {
    public static void method(List<Interface> list){
    }

    public static void main(String[] args) {
        List <Enum> enumList = new ArrayList<Enum>();
        method(enumList); //This line gives the compile error.
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么会出现编译错误?对我而言,它似乎应该工作,因为Enum实现了该接口.

java generics enums

0
推荐指数
1
解决办法
261
查看次数

标签 统计

enums ×1

generics ×1

java ×1

xml ×1

xpath ×1

xslt ×1