我有:
List<WatchEvent.Kind<Path>> events_kinds = new ArrayList<>();
events_kinds.add(StandardWatchEventKinds.ENTRY_DELETE);
events_kinds.add(StandardWatchEventKinds.ENTRY_CREATE);
events_kinds.add(StandardWatchEventKinds.ENTRY_MODIFY);
比我想使用register
接受类型作为第二个参数的方法,Kinds<?>[]
所以我这样做:
WatchKey key = path.register(watch_service, (WatchEvent.Kind<Path>[]) events_kinds.toArray());
但是当我执行代码时,出现以下异常:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.nio.file.WatchEvent$Kind;
现在如何Kinds<?>[]
从该列表中获取数组?
谢谢。