我不明白克隆自定义对象的机制.例如:
public class Main{
public static void main(String [] args) {
Person person = new Person();
person.setFname("Bill");
person.setLname("Hook");
Person cloned = (Person)person.clone();
System.out.println(cloned.getFname() + " " + cloned.getLname());
}
}
class Person implements Cloneable{
private String fname;
private String lname;
public Object clone() {
Person person = new Person();
person.setFname(this.fname);
person.setLname(this.lname);
return person;
}
public void setFname(String fname) {
this.fname = fname;
}
public void setLname(String lname){
this.lname = lname;
}
public String getFname(){
return fname;
}
public String getLname() …Run Code Online (Sandbox Code Playgroud) 我的非常简单的Web应用程序出了什么问题:Web应用程序成功部署到app服务器但是hello bean没有注入index.xhtml页面(页面显示来自Facelets的Hello:#{hello.value})?
(这是我第一次使用JSF,所以也许这个问题很容易,而且我也使用了很好的文章http://arjan-tijms.omnifaces.org/2011/08/minimal-3-tier-java- ee-app-without-any.html)
我有下一个战争档案结构:
mywebapp
|
- WEB_INF
|
- classes
|
- Hello.class
- index.html
Run Code Online (Sandbox Code Playgroud)
Hello.java有:
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
@Named
@RequestScoped
public class Hello {
private String value;
public String getValue() {
return "Hello JSF";
}
public void setValue(String value) {
this.value = value;
}
}
Run Code Online (Sandbox Code Playgroud)
还有我的index.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>My Facelet Page Title</title>
</h:head>
<h:body>
Hello from Facelets: #{hello.value}
</h:body>
</html> …Run Code Online (Sandbox Code Playgroud) 这是停止线程的好例子. 如何优雅地停止java线程? - 感谢同性恋者:)但是当我尝试检查这个例子时,我收到了无限循环.你能帮助我吗?这是我的代码
public class Num{
public void crash(ManualStopping t1) {
t1.stopMe();
}
public static void main(String [] args) {
Num num = new Num();
ManualStopping t1 = new ManualStopping();
t1.run();
System.out.println("Main thread");
num.crash(t1);
}
Run Code Online (Sandbox Code Playgroud)
}
class ManualStopping extends Thread{
volatile boolean finished = false;
public void stopMe(){
finished = true;
}
public void run() {
while(!finished){
System.out.println("I'm alive");
}
}
Run Code Online (Sandbox Code Playgroud)
}