strictfp修饰符的作用是使接口声明中的所有float或double表达式都是显式FP-strict(第15.4节).
这意味着在接口中声明的所有嵌套类型都是隐式strictfp.
strictfp修饰符的作用是使接口声明中的所有float或double表达式都是显式FP-strict(第15.4节).
这意味着在接口中声明的所有方法以及在接口中声明的所有嵌套类型都是隐式strictfp.
从这两段开始,没有任何迹象表明strictfp在实现/扩展使用strictfp修饰符声明的接口/类时的行为.
在搜索之后,我找到了strictfp关键字用法的一个很好的解释使用strictfp修饰符来实现跨平台的浮点计算一致性,并指定:
扩展FP严格超类的子类不会继承严格的行为.当重写方法不是时,重写方法可以独立地选择FP-strict,反之亦然.
我strictfp在扩展使用strictfp关键字声明的类时测试了关键字的行为,这是正确的:strictfp行为不是由扩展类的类继承的,但问题是在实现用strictfp关键字声明的接口时它是不正确的:strictfp行为不是由实现的类继承的界面.
任何人都可以解释我strictfp实现/扩展使用strictfp修饰符声明的接口/类的正确行为吗?
从JDK 5.0开始,自动装箱/拆箱是在java中引入的,技巧简单而有用,但是当我开始测试包装类和原始类型之间的不同转换时,我真的很困惑自动装箱的概念如何在java中工作,例如:
拳击
int intValue = 0;
Integer intObject = intValue;
byte byteValue = 0;
intObject = byteValue; // ==> Error
Run Code Online (Sandbox Code Playgroud)
尝试不同的情况下(后short,long,float,double),这是由编译器所接受的唯一情况是,当值的上做作运算符右侧的类型是int.当我查看我的源代码时Integer.class发现它只实现了一个带int参数的构造函数.
所以我的结论是自动装箱的概念是基于包装类中实现的构造函数.我想知道这个结论是否属实,还是有自动拳击使用的另一个概念?
拆箱
Integer intObject = new Integer(0);
byte byteValue = intObject; // ==> Error (the same Error with short)
int intValue = intObject;
double doubleValue = intObject;
Run Code Online (Sandbox Code Playgroud)
关于拆箱的结论是包装类给出了对应的类型(Integer==> int)包装的值,然后编译器使用通常的转换基元类型的规则(byte=> short=> int=> long=> float=> double).我想知道这个结论是否属实,还是自动拆箱使用了另一个概念? …
在阅读关于集合实现的Oracle教程时,我发现了以下句子:
如果您需要同步,则a
Vector将比ArrayList同步的稍快Collections.synchronizedList
来源:列表实现
但是当搜索它们之间的差异时,许多人不鼓励使用,Vector并且应该在SynchronizedList需要同步时替换.那么哪一方有权被追随?
我尝试ArrayType[]::new在以下示例中使用带有表达式的引用方法:
public class Main
{
public static void main(String[] args)
{
test1(3,A[]::new);
test2(x -> new A[] { new A(), new A(), new A() });
test3(A::new);
}
static void test1(int size, IntFunction<A[]> s)
{
System.out.println(Arrays.toString(s.apply(size)));
}
static void test2(IntFunction<A[]> s)
{
System.out.println(Arrays.toString(s.apply(3)));
}
static void test3(Supplier<A> s)
{
System.out.println(s.get());
}
}
class A
{
static int count = 0;
int value = 0;
A()
{
value = count++;
}
public String toString()
{
return Integer.toString(value);
}
}
Run Code Online (Sandbox Code Playgroud)
产量
[null, …Run Code Online (Sandbox Code Playgroud) 如果这些信息是否正确,任何人都可以确认我:
在C++中,在catch块中我们可以使用throw语句重新抛出异常,但抛出的异常应该与当前捕获的异常具有相同的类型.
在具有Oracle JDK 10.0.1-64bits的Ubuntu Mate 18.04-64bits上使用jmap时,该工具仅在同时以root身份运行目标和工具时才有效,但是使用同一普通用户运行这两者会产生以下错误:
Exception in thread "main" com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file /proc/13538/cwd/.attach_pid13538: target process 13538 doesn't respond within 10500ms or HotSpot VM not loaded
at jdk.attach/sun.tools.attach.VirtualMachineImpl.<init>(VirtualMachineImpl.java:103)
at jdk.attach/sun.tools.attach.AttachProviderImpl.attachVirtualMachine(AttachProviderImpl.java:58)
at jdk.attach/com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:207)
at jdk.jcmd/sun.tools.jmap.JMap.executeCommandForPid(JMap.java:124)
at jdk.jcmd/sun.tools.jmap.JMap.main(JMap.java:114)
Run Code Online (Sandbox Code Playgroud)
使用root用户运行以下命令时
jmap -clstats <pid>
Run Code Online (Sandbox Code Playgroud)
谁能向我解释为什么第一个线程不起作用而第二个线程完美运行:
public class Test {
public static void main(String args[]) throws InterruptedException {
TestThread1 t1 = new TestThread1();
TestThread2 t2 = new TestThread2();
t1.startThread();
t2.start();
Thread.sleep(4000);
t1.stopThread();
t2.stopThread();
}
}
class TestThread1 extends Thread {
private volatile TestThread1 thread;
public void startThread() {
thread = new TestThread1();
thread.start();
}
public void run() {
while (thread != null) {
System.out.println("RUNNING 1 ...");
}
}
public void stopThread() {
thread = null;
}
}
class TestThread2 extends Thread {
private volatile boolean …Run Code Online (Sandbox Code Playgroud) java ×6
autoboxing ×1
c++ ×1
collections ×1
exception ×1
extends ×1
implements ×1
java-8 ×1
jmap ×1
list ×1
strictfp ×1
throw ×1
unboxing ×1