我无法将字节转换为流.有一个简单的方法吗?
Stream stream;
stream = (Stream) vByte; //something is going wrong in this part.
//vByte is a byte variable
Run Code Online (Sandbox Code Playgroud) 代码
class TestException extends Exception {
}
interface Task<E extends Exception> {
void call() throws E;
}
public class TaskPerformer {
/** performs a task in the proper context, rethrowing any exceptions the task declares */
private <E extends Exception> void perform(Task<E> task) throws E {
beforeTask();
try {
task.call();
} finally {
afterTask();
}
}
private void afterTask() {
// implementation elided (does not matter)
}
private void beforeTask() {
// implementation elided (does not matter)
}
public static …Run Code Online (Sandbox Code Playgroud) 我想告知用户HTTP请求是否失败,而不必为每个HTTP请求编写额外的代码.
我有角度2的工作原型:
@Injectable()
export class MyErrorHandler extends ErrorHandler {
constructor() {
super(false);
}
handleError(error: any) {
this.tellUser(error);
super.handleError(error);
}
tellUser(error: any) {
// dig for the root cause
if (error.rejection) {
error = error.rejection;
}
if (error instanceof ViewWrappedError) {
error = error.originalError;
}
let message;
if (error instanceof Response) {
// TODO: localize and display nicely
const messages = {
0: "Could not connect to server",
}
message = messages[error.status] || ("The server reported a system error (HTTP " …Run Code Online (Sandbox Code Playgroud) ArrayList描述为
public class ArrayList<E> extends AbstractList<E>
implements List<E>, RandomAccess, Cloneable, java.io.Serializable
Run Code Online (Sandbox Code Playgroud)
而且大多数主要方法都适用于E泛型类型(get,set,add,addAll等)。
但是方法contains,indexOf,lastIndexOf和remove将对象类型作为参数-这仅是由于内部使用或Object.equals()或其他原因吗?
我正在创建一个类似于Banko applet的Java应用程序.当我点击"public void init()"方法时,我的表现很好.当我完成时,除了那之外所有编译.它告诉我添加@Override注释.我试过了,但每当我这样做,无论我把它放在哪里,编译器都会失败并出现以下错误:
找不到标志
符号:类覆盖
location:class aBomb.Bomb
我不知道是什么阻止了应用程序正常执行.:| 如果您在下面写的代码中找到了您认为应该更改的内容,请告诉我.我是Java的新手:(代码:
public void init() {
BorderLayout border = new BorderLayout();
setLayout(border);
JPanel top = new JPanel();
JLabel moneyLabel = new JLabel("Money : $");
moneyField = new JTextField("", 8);
moneyField.setEditable(false);
JLabel foundLabel = new JLabel("Found: ");
foundField = new JTextField("", 8);
foundField.setEditable(false);
restart = new JButton("Restart");
restart.addActionListener(this);
top.add(moneyLabel);
top.add(moneyField);
top.add(foundLabel);
top.add(foundField);
top.add(restart);
add(top, BorderLayout.NORTH);
board = new Board(this, ROW_COUNT, COLUMN_COUNT, BOMB_COUNT);
add(board, BorderLayout.CENTER);
setup();
setVisible(true);
}
Run Code Online (Sandbox Code Playgroud) 我有一个实用程序函数,它将随机播放任何Vector的元素,但会生成有关使用原始类型的一般警告.
static public void shuffle(Random r,Vector v)
{ int sz = v.size();
for(int pass = 0;pass<4;pass++)
{ for(int i=0;i<sz;i++)
{ int j=nextInt(r,sz);
Object ii = v.elementAt(i);
v.setElementAt(v.elementAt(j),i);
v.setElementAt(ii,j);
}
}
}
Run Code Online (Sandbox Code Playgroud)
似乎除了通过压制它们之外似乎没有办法安静警告.更改方法签名以Vector<Object>
限制调用者Vector<Object>.更改为Vector<?>使setElementAt 无法编译.
package com.shaun.spring.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan("com.shaun.spring")
@EnableTransactionManagement
public class ApplicationContextConfig {
// @Bean configurations go here...
}
Run Code Online (Sandbox Code Playgroud)
我对@EnableTransactionManagement 有问题,发生的以下错误是:EnableTransactionManagement 无法解析为类型。
我的 pom.xml 中有以下依赖项:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用以下导入:
import org.springframework.transaction.annotation.EnableTransactionManagement;
Run Code Online (Sandbox Code Playgroud)
这给了我以下错误:
The import org.springframework.transaction.annotation.EnableTransactionManagement cannot be resolved
Run Code Online (Sandbox Code Playgroud) $ javac GetAllDirs.java
GetAllDirs.java:16: cannot find symbol
symbol : variable checkFile
location: class GetAllDirs
System.out.println(checkFile.getName());
^
1 error
$ cat GetAllDirs.java
import java.util.*;
import java.io.*;
public class GetAllDirs {
public void getAllDirs(File file) {
if(file.isDirectory()){
System.out.println(file.getName());
File checkFile = new File(file.getCanonicalPath());
}else if(file.isFile()){
System.out.println(file.getName());
File checkFile = new File(file.getParent());
}else{
// checkFile should get Initialized at least HERE!
File checkFile = file;
}
System.out.println(file.getName());
// WHY ERROR HERE: checkfile not found
System.out.println(checkFile.getName());
}
public static void main(String[] args) {
GetAllDirs …Run Code Online (Sandbox Code Playgroud)