好吧,我正在挖掘Java8 lambda,我正面临以下问题 - lambda不会改变数据:
DamnLambda.class:
public static void inc ( List<Integer> list, Funtion<Integer,Integer> func) {
for(Integer intr : list) {
intr = func.apply(intr);
}
Run Code Online (Sandbox Code Playgroud)
我们试着调用:
List<Integer> l = Arrays.asList(1,2,3);
DamnLambda.inc(l, x -> x+=1);
System.out.println(l); //[1,2,3] ? Why not [2,3,4] ?
Run Code Online (Sandbox Code Playgroud)
我无法理解为什么它不会改变任何数据.我也尝试了不同版本的相同功能:
l.forEach(x -> x+1); //same thing, doesn't change the data.
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么?
我有strcpy函数的问题.使用C.这个简单代码(下面)的要点是将字符串从数组复制到指针数组.
char string[20] = "ABCDEFGH\0";
char * array_of_pointers[20];
// now I want to copy string to the first available slot;
strcpy(array_of_pointers[0],string);
Run Code Online (Sandbox Code Playgroud)
然后strcpy抛出我的错误:
Unhandled exception: Access violation writing location 0x00000000.
Run Code Online (Sandbox Code Playgroud)
为什么?我知道这个问题可能很简单,但我真的没有线索.
是否java.util Optional.ofNullable工作正常使用的Mockito?
在代码执行期间,我遇到这样的事情:
User user = Optional.ofNullable(userProviderMock.findUser()).orElse(someMethod())
Run Code Online (Sandbox Code Playgroud)
我设置我的模拟行为如下:
when(userProviderMock.findUser()).thenReturn(new User());
Run Code Online (Sandbox Code Playgroud)
当我运行它时,userProviderMock返回new User()(调试确认),但不知何故someMethod()仍然执行.我真的不知道为什么会这样.有线索吗?
表:
玩家
player_no | transaction_id
----------------------------
1 | 11
2 | 22
3 | (null)
1 | 33
Run Code Online (Sandbox Code Playgroud)
交易
id | value |
-----------------------
11 | 5
22 | 10
33 | 2
Run Code Online (Sandbox Code Playgroud)
我的目标是获取所有数据,维护所有玩家,即使null是以下查询中的值:
SELECT p.player_no, COUNT(p.player_no), SUM(t.value) FROM Players p
INNER JOIN Transactions t ON p.transaction_id = t.id
GROUP BY p.player_no
Run Code Online (Sandbox Code Playgroud)
然而,结果省略了空值,例如:
player_no | count | sum
------------------------
1 | 2 | 7
2 | 1 | 10
Run Code Online (Sandbox Code Playgroud)
我想提到的是空值:
player_no | count | sum
------------------------
1 | …Run Code Online (Sandbox Code Playgroud) 好吧,我有一个奇怪的问题printf().它在屏幕上输出垃圾.我想这与记忆有关.看一看:
char string1[] = "SAMPLE STRING";
char string2[20]; // some garbage in it
/* let's clear this madness*/
int i = 0;
for (i; i < 20; i++) string2[i] = ' '; // Space, why not.
printf("output: %s", string2);
Run Code Online (Sandbox Code Playgroud)
OUTPUT
output: ???????????????????????????SAMPLE STRING
// ten spaces and random characters, why?
Run Code Online (Sandbox Code Playgroud) 我坚持使用我的代码20分钟.
这个简单的C代码有什么问题?
void function (char & reference_to_something) {}
Run Code Online (Sandbox Code Playgroud)
错误:
expected ';' , ',' or ')' before '&' token
Run Code Online (Sandbox Code Playgroud)