我有一个声明如下的泛型方法
public static <E extends Number> List<E> myListOfElements(List<E> list) {
return new ArrayList<Integer>();
}
Run Code Online (Sandbox Code Playgroud)
我从中理解的是它期望一个类型的List Number
作为输入扩展,List类型Number
作为输出扩展.当我尝试返回一个ArrayList<Integer>
r时,它会产生编译错误
Type mismatch: cannot convert from ArrayList<Integer> to List<E>
Run Code Online (Sandbox Code Playgroud)
我不明白这里有什么问题.为什么我不能回到ArrayList<Integer>
这里?
我有以下一段java代码:
CompletableFuture<String> future1 = CompletableFuture.supplyAsync(() -> {
try {
Thread.sleep(3);
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
return "Result of Future 1";
});
CompletableFuture<String> future2 = CompletableFuture.supplyAsync(() -> {
try {
Thread.sleep(3);
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
return "Result of Future 2";
});
CompletableFuture<String> future3 = CompletableFuture.supplyAsync(() -> {
try {
Thread.sleep(3);
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
return "Result of Future 3";
});
boolean isdone = CompletableFuture.allOf(future1, future2, future3).isDone();
if …
Run Code Online (Sandbox Code Playgroud) 我想公开一个 API,以将 S3 存储桶文件内容作为流下载给其使用者。API URL 就像 /downloadfile/** 这是 GET 请求。
这是我写到现在的控制器伪代码,它一直给我 406 错误。
@GetMapping(value = "/downloadfile/**", produces = { MediaType.APPLICATION_OCTET_STREAM_VALUE })
public ResponseEntity<Object> downloadFile(HttpServletRequest request) {
//reads the content from S3 bucket and returns a S3ObjectInputStream
S3ObjectInputStream object = null;
object = publishAmazonS3.getObject("12345bucket", "/logs/file1.log").getObjectContent();
return object
}
Run Code Online (Sandbox Code Playgroud)
这里有什么关于这样做的建议以及我做错了什么?
我有以下课程:
class Data {
String systemId;
String fileName;
int x;
int y;
Data(String systemId, String fileName, int x, int y) {
this.systemId = systemId;
this.fileName = fileName;
this.x = x;
this.y = y;
}
public String getSystemId() {
return systemId;
}
public void setSystemId(String systemId) {
this.systemId = systemId;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = …
Run Code Online (Sandbox Code Playgroud) 我使用 React Router 路由到不同的路由,如下所示:
<Router>
<Switch>
<Route path="/teams/:teamName/matches" >
<MatchPage/>
</Route>
<Route path="/teams/:teamName" >
<TeamPage/>
</Route>
</Switch>
</Router>
Run Code Online (Sandbox Code Playgroud)
现在,在我的TeamPage
组件中,我使用调用 API async
,然后在渲染方法中调用另一个名为的组件MatchDetailCard
class TeamPage extends Component {
constructor(props) {
console.log('const called')
super(props)
this.state = {
team: [],
teamName:null
}
}
async componentDidMount() {
console.log(this.props.match.params.teamName);
const teamName = this.props.match.params.teamName;
const response = await fetch(`http://localhost:8080/team/${teamName}`);
const json = await response.json();
console.log(json);
this.setState({team:json, teamName: teamName});
}
componentDidUpdate () {
console.log('updated')
}
render() {
if (!this.state.team || !this.state.team.teamName) {
return <h1>Team …
Run Code Online (Sandbox Code Playgroud) java ×4
java-8 ×2
amazon-s3 ×1
generics ×1
java-stream ×1
react-router ×1
reactjs ×1
spring-boot ×1