package com.company;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.List;
public class Main {
@Target(ElementType.TYPE_USE)
@Retention(RetentionPolicy.RUNTIME)
public @interface A {}
public static void main(String[] args) {
}
private List<@A Integer> integers1;
private List<@A java.lang.Integer> integers2;
}
Run Code Online (Sandbox Code Playgroud)
我收到
private List<@A java.lang.Integer> integers2;
错误:
错误:(20, 21) java: 找不到符号符号:类 java
位置:类 com.company.Main
是程序中的bug吗?
我有简单的应用程序代码:
webView.getEngine().load("classpath:data/index.html");
Run Code Online (Sandbox Code Playgroud)
自定义URLStreamHandler:
public class Handler extends URLStreamHandler {
private final ClassLoader classLoader;
public Handler() {
this.classLoader = getClass().getClassLoader();
}
public Handler(ClassLoader classLoader) {
this.classLoader = classLoader;
}
@Override
protected URLConnection openConnection(URL u) throws IOException {
URL resourceUrl = classLoader.getResource(u.getPath());
if(resourceUrl == null)
throw new IOException("Resource not found: " + u);
return resourceUrl.openConnection();
}
}
Run Code Online (Sandbox Code Playgroud)
安装人:
URL.setURLStreamHandlerFactory(protocol -> {
if(protocol.equals("classpath")) {
return new Handler();
} else {
return null;
}
});
Run Code Online (Sandbox Code Playgroud)
它加载data/index.html:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<div>Hello, …Run Code Online (Sandbox Code Playgroud)