我想知道是否可以将lambda存放在某个容器中,例如.ArrayList或HashMap.我想更改该代码:
public enum OPCODE implements BinaryOperator<Integer> {
MOV((x, y) -> y),
INC((x, y) -> ++x),
DEC((x, y) -> --x),
ADD((x, y) -> x + y),
SUB((x, y) -> x - y);
private final BinaryOperator<Integer> binaryOperator;
OPCODE(BinaryOperator<Integer> binaryOperator) {
this.binaryOperator = binaryOperator;
}
@Override
public Integer apply(Integer integer, Integer integer2) {
return binaryOperator.apply(integer, integer2);
}
}
Run Code Online (Sandbox Code Playgroud)
对于这样的事情:
List<BinaryOperator<Integer>> opcodes = new ArrayList<BinaryOperator<Integer>>(){
((x, y) -> y),
((x, y) -> ++x)
};
Run Code Online (Sandbox Code Playgroud)
等等
并像这样使用它:
opcodes[0].apply(a, b);
Run Code Online (Sandbox Code Playgroud)
甚至可能吗?
如何使用Optionals将此函数重写为更多Java 8?或者我应该保持原样?
public void setMemory(ArrayList<Integer> memory) {
if (memory == null)
throw new IllegalArgumentException("ERROR: memory object can't be null.");
if (memory.contains(null))
throw new IllegalArgumentException("ERROR: memory object can't contain null value.");
this.memory = memory;
}
Run Code Online (Sandbox Code Playgroud) 我想知道如何在测试时禁用Elixir中的日志记录.在我当前的代码中,我测试记录器消息,所以我不想完全禁用它,但隐藏消息直到任何测试停止传递.
我正在使用mix和ExUnit来管理和测试我的项目.
mix test
Compiling 2 files (.ex)
.........
17:59:18.446 [warn] Code seems to be empty
.
17:59:18.447 [warn] Code doesn't contain HLT opcode
.
17:59:18.448 [warn] Code doesn't contain HLT opcode
17:59:18.448 [error] Label error doesn't exist
.....
Finished in 0.07 seconds
16 tests, 0 failures
Run Code Online (Sandbox Code Playgroud) 我今天开始使用Log4j 2,我看到了三种指定消息级别的方法:1.使用filter.threshold 2.在appender本身中 3.或在rootLogger中 指定logger的消息级别时推荐使用哪种方式?
我目前将此代码作为 Log4j2 conf 文件:
status = error
dest = err
name = PropertiesConfig
property.filename = logs/log.log
filter.threshold.type = ThresholdFilter
filter.threshold.level = trace
appender.console.type = Console
appender.console.name = ConsoleLogger
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%t.%-15c{1}] [%p] %d{HH:mm:ss.SSS} - %m%n
appender.console.filter.threshold.type = ThresholdFilter
appender.console.filter.threshold.level = trace
appender.randomAccessFile.type = RandomAccessFile
appender.randomAccessFile.name = File
appender.randomAccessFile.filename = logs/log.log
appender.randomAccessFile.immediateFlush = false
appender.randomAccessFile.append = false
appender.randomAccessFile.layout.type = PatternLayout
appender.randomAccessFile.layout.pattern = %-10[%t.%c{1}] [%p] %d{HH:mm:ss.SSS} - %m%n
appender.randomAccessFile.filter.threshold.type = ThresholdFilter
appender.randomAccessFile.filter.threshold.level = trace …Run Code Online (Sandbox Code Playgroud) 我想知道如何转换ArrayList<String>为ArrayList<Integer>.
我有这个代码:
ArrayList<String> sNumbers = new ArrayList<String>();
ArrayList<Integer> numbers = new ArrayList<Integer>();
numbers.add(1);
numbers.add(2);
numbers.add(3);
sNumbers.add(numbers.toString());
System.out.println(sNumbers);//for testing
Run Code Online (Sandbox Code Playgroud)
我明白了:
[[1, 2, 3]]
Run Code Online (Sandbox Code Playgroud)
这就是我的问题:如何扭转这一过程(获取一行数字并将其放入数字中ArrayList)
它应该是这样的:
sNumbers
0 [1, 2, 3] -->
numbers
0 [1]
1 [2]
2 [3]
(without brackets)
Run Code Online (Sandbox Code Playgroud) 是否有任何类可以通过不同的音调在扬声器中发出声音?System.Beep() 是原始的,我无法以双倍形式发送频率。
比如说,我想要播放 A 声音或 B# 声音。我希望函数调用如下:
double d = 425,545;
int duration = 500;
int volume = 0.8;
f(d, duration, volume)
f(ToneClass.A, duration, volume)//or like this
Run Code Online (Sandbox Code Playgroud) 如何使用数组初始化List <>?喜欢:
List<string> list = new List<string>();
string[] str = new string[5];
list = str;
Run Code Online (Sandbox Code Playgroud)