我有以下代码.
class Test {
int i = 0;
Test() {
System.out.println(this);
System.out.println(this.i);
}
}
public class Demo extends Test {
int i = 10;
Demo() {
super();
System.out.println("calling super");
System.out.println(this);
System.out.println(this.i);
}
public static void main(String[] args) throws IOException {
Demo d = new Demo();
}
}
O/P : Demo@2e6e1408
0
calling super
Demo@2e6e1408
10
Run Code Online (Sandbox Code Playgroud)
当我执行程序并打印"this"的值时,在超类构造函数和子类构造函数中,this(地址位置)的值显示为childClassName @ someValue ..我的问题是,为什么不是我当我在超类中打印"this"的值时,得到Test的值,即Test @ someVal(Super class).. ASAIK,Super class也会在内存中有一个位置/位置,所以,为什么我没有得到Test @someValue在第一个SOP ......
PS:我知道基于引用类型(LHS)引用变量,并且基于对象类型(RHS)调用方法.
我想从JavaFX datepicker获取值并将值存储为Date Object:
final DatePicker datePicker = new DatePicker(LocalDate.now());
Date date = datePicker.getValue();
grid.add(datePicker, 1, 9);
Run Code Online (Sandbox Code Playgroud)
你能告诉我怎么转换LocalDate成Date?
我不明白我怎么能改写用于jetty 6的jetty 6的代码:
import org.mortbay.jetty.*;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.webapp.WebAppContext;
public class ApplLauncher {
public static void main(String[] args) {
Server server = new Server();
Connector connector = new SelectChannelConnector();
connector.setPort(8080);
server.addConnector(connector);
WebAppContext root = new WebAppContext("C:\\Users\\OZKA\\IdeaProjects\\projectname\\projectname\\web", "/");
root.setWelcomeFiles(new String[]{"index.html"});
//root.addServlet(new ServletHolder(new TestServlet()), "/test");
server.setHandlers(new Handler[]{root});
try {
server.start();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码工作正常,并响应web.xml中映射的web文件夹和servlet中的静态内容.这是我尝试使用嵌入式码头9:
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.Handler;
public class ApplLauncher {
public static void …Run Code Online (Sandbox Code Playgroud) 码:
public void placeO(int xpos, int ypos) {
for(int i=0; i<3;i++)
for(int j = 0;j<3;j++) {
// The line below does not work. what can I use to replace this?
if(position[i][j]==' ') {
position[i][j]='0';
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个双阵列doubleArray1.我尝试了Arrays.asList().contains()如下所示的操作
double doubleArray1 [] = {1D,2D,3D};
if(Arrays.asList(doubleArray1).contains(1D)) {
System.out.println("hello-1");
}
Run Code Online (Sandbox Code Playgroud)
它不打印任何东西.然后我把它变成了一个Double数组
Double doubleArray1 [] = {1D,2D,3D};
if(Arrays.asList(doubleArray1).contains(1D)) {
System.out.println("hello-1");
}
Run Code Online (Sandbox Code Playgroud)
它打印hello-1.
有人能解释为什么会有这种差异