以下方法是名为election_date的字段的setter,其类型为java.util.date.它是tomcat应用程序的一部分.
执行时,我在行上得到一个Null指针异常:
System.out.println("ELECTION DATE: " + this.election_date.toString());
Run Code Online (Sandbox Code Playgroud)
public void setElection_date(Date election_date) {
this.election_date = election_date;
assert (this.election_date != null);
assert (this.election_date.toString()) != null;
System.out.println("ELECTION DATE: " + this.election_date.toString());
}
Run Code Online (Sandbox Code Playgroud)
编辑:请不要告诉我这是垃圾收集.我可能稍微离开巴尔默峰,但距离那不远.
是否有最简单的方法可以在下面编写此代码而不使用toStream()
?
import io.vavr.collection.List;
import io.vavr.control.Option;
import lombok.Value;
public class VavrDemo {
public static void main(String[] args) {
Foo bar = new Foo(List.of(new Bar(1), new Bar(2)));
Number value = Option.some(bar)
.toStream() // <- WTF?!?
.flatMap(Foo::getBars)
.map(Bar::getValue)
.sum();
System.out.println(value);
}
@Value
static class Foo {
private List<Bar> bars;
}
@Value
static class Bar {
private int value;
}
}
Run Code Online (Sandbox Code Playgroud) 我有两个引用,引用一个指向对象a,引用b指向对象b,然后我调用一个交换函数试图让一个指向对象b,b指向对象a,它在交换函数中交换,但是主要功能的结果没有改变.那我该怎么办?
交换功能:
private void swap(Stack<TreeNode> a, Stack<TreeNode> b) {
Stack<TreeNode> temp = new Stack<TreeNode>();
temp = a;
a = b;
b = temp;
}
Run Code Online (Sandbox Code Playgroud) 根据我的理解,非静态方法的同步将在对象级别被阻止,并且静态方法上的同步将在类实例级别被阻止.
基于此,请在下面找到我对各种场景的理解:
非静态同步方法访问然后其他非静态同步方法也阻塞
非静态同步方法访问然后非静态非同步方法不阻塞.
static synchrnize方法访问然后阻止该类实例的其他同步(静态和非静态)方法.
静态同步方法访问然后其他非静态非同步方法不会阻塞.
静态同步方法访问然后其他静态非同步方法不阻止.
静态同步方法访问然后阻止所有对象实例的非静态同步方法.
非静态synchrnize方法访问然后静态同步方法不阻塞
请帮我核实一下.
boolean flag = new
File("C:/Users/Username/somefolder/.../somefolder/somename.ogg").isFile();
System.out.println("isFile: " + flag);
Run Code Online (Sandbox Code Playgroud)
返回:
isFile: false
Run Code Online (Sandbox Code Playgroud)
我想作为文件出现.我究竟做错了什么?
您好我正在研究gcd和逆模运算的算法.
我必须使用BigInteger类,但我有一些问题.
那你能帮我吗?
问题是java programm不想用新的输入覆盖旧的BigInteger输入.
import java.math.BigInteger;
public class Gcd
{
public static void gcd(BigInteger a, BigInteger b){
BigInteger modulo = b;
BigInteger wert = a;
BigInteger zwischenwert1 = BigInteger.valueOf(1);
BigInteger zwischenwert2 = BigInteger.valueOf(0);
BigInteger zwischenwert3 = BigInteger.valueOf(0);
BigInteger zwischenwert4 = BigInteger.valueOf(1);
BigInteger negativ = BigInteger.valueOf(-1);
BigInteger q;
do{
q = modulo.divide(wert);
wert = modulo.subtract(wert.multiply(q));
zwischenwert3 = zwischenwert1.subtract(zwischenwert3.multiply(q));
zwischenwert4 = zwischenwert2.subtract(zwischenwert4.multiply(q));
modulo = negativ.multiply((wert.subtract(modulo)).divide(q));
zwischenwert1 = negativ.multiply((zwischenwert3.subtract(zwischenwert1)).divide(q));
zwischenwert2 = negativ.multiply((zwischenwert4.subtract(zwischenwert2)).divide(q));
}while((modulo.signum()>1)&&(wert.signum()>1));
System.out.println("gcd("+a+","+b+") = "+zwischenwert3+" * "+b+ " + "+ zwischenwert4+" …
Run Code Online (Sandbox Code Playgroud) java ×6
algorithm ×1
assert ×1
biginteger ×1
bluej ×1
directory ×1
file ×1
java-stream ×1
modulo ×1
synchronize ×1
vavr ×1