小编Buf*_*lls的帖子

为什么Java8 Stream什么都不生成?

import java.util.Comparator;
import java.util.PriorityQueue;


public class TestPQ {
    public static void main(String[] args){
        Comparator<String> comparator = new StringLengthComparator();
        PriorityQueue<String> queue = new PriorityQueue<String>(10, comparator);
        queue.offer("Short");
        queue.offer("ABCahahahha");
        queue.offer("lululu");
        queue.stream().map( s-> {
            System.out.println("queue: "+ s);
            return s;
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

我有这个代码,我希望我会看到"短片","lululu"和"ABCahahahha"被打印出来.但我没有看到他们.我的代码出了什么问题?编译很好.我正在使用java 8编译器和运行时.

java-8 java-stream

5
推荐指数
2
解决办法
251
查看次数

是invokeAll()在java 7中的阻塞调用

ExecutorService executorService = Executors.newSingleThreadExecutor();

Set<Callable<String>> callables = new HashSet<Callable<String>>();

callables.add(new Callable<String>() {
    public String call() throws Exception {
        return "Task 1";
    }
});
callables.add(new Callable<String>() {
    public String call() throws Exception {
        return "Task 2";
    }
});
callables.add(new Callable<String>() {
    public String call() throws Exception {
        return "Task 3";
    }
});

List<Future<String>> futures = executorService.invokeAll(callables);

for(Future<String> future : futures){
    System.out.println("future.get = " + future.get());
}
Run Code Online (Sandbox Code Playgroud)

对于这段代码.我的问题是"是invokeAll()阻塞调用"?我的意思是,当代码运行到invokeAll()行时,我们是否在那里等待所有结果生成?

java concurrency multithreading

5
推荐指数
1
解决办法
2814
查看次数

如何实现pow(双x,双y)?

我知道如何推动战俘(双x,中国)

public class Solution {
    public double myPow(double x, int n) {
        if (n == 0)
            return 1;

        if (n % 2 == 0) {
            return myPow(x * x, n / 2);
        } else {
            if (n > 0)
                return x * myPow(x, n - 1);
            else
                return 1 / x * myPow(x, n + 1);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是如何使它处理双y?

java algorithm math

5
推荐指数
1
解决办法
496
查看次数

写()上的Gcc和g ++不同

#include <sys/syscall.h>
#define BUFSIZE 1024

main()
{
     char buf[BUFSIZE];
     int n;
     while((n=read(0,buf,BUFSIZE))>0)
         write(1,buf,n);
     return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我使用gcc编译它时,它很好.但是使用g ++我得到了:

inandout.c:7:32: error: ‘read’ was not declared in this scope
     while((n=read(0,buf,BUFSIZE))>0)
                                ^
inandout.c:8:22: error: ‘write’ was not declared in this scope
         write(1,buf,n);
                      ^
Run Code Online (Sandbox Code Playgroud)

这是为什么?

c

4
推荐指数
1
解决办法
1万
查看次数

去原子加载和存储

func resetElectionTimeoutMS(newMin, newMax int) (int, int) {
    oldMin := atomic.LoadInt32(&MinimumElectionTimeoutMS)
    oldMax := atomic.LoadInt32(&maximumElectionTimeoutMS)
    atomic.StoreInt32(&MinimumElectionTimeoutMS, int32(newMin))
    atomic.StoreInt32(&maximumElectionTimeoutMS, int32(newMax))
    return int(oldMin), int(oldMax)
}
Run Code Online (Sandbox Code Playgroud)

我得到了这样的代码函数.我感到困惑的是:我们为什么需要atomic这里?这是什么阻止了?

谢谢.

go raft

4
推荐指数
1
解决办法
2448
查看次数

scala set.contains的实现

type Set = Int => Boolean
/**
* Indicates whether a set contains a given element.
*/
def contains(s: Set, elem: Int): Boolean = s(elem)
Run Code Online (Sandbox Code Playgroud)

为什么这个contains功能有效?

我不明白.()操作符如何在集合中返回true/ false关于此元素的存在?

scala

4
推荐指数
1
解决办法
986
查看次数

在进行中,如果我们要使用该文件中定义的功能,是否不需要在同一目录中导入另一个文件?

在进行中,如果我们要使用该文件中定义的功能,是否不需要在同一目录中导入另一个文件?例如。

FolderA-
-------- FileA.go
---------FileB.go
Run Code Online (Sandbox Code Playgroud)

在FileB.go中,我定义方法Foo()

在FileA.go中,我想调用FileB.go中定义的Foo()。

我需要像这样在FileA.go中导入FileB吗?

import ("FileB")
Run Code Online (Sandbox Code Playgroud)

go

4
推荐指数
2
解决办法
6480
查看次数

fork(3)和fork(2)之间的区别

我粗略阅读

http://linux.die.net/man/2/forkhttp://linux.die.net/man/3/fork

感到困惑.谁能简单地向我解释一下fork(3)和fork(2)之间的区别谢谢

c linux fork system-calls

3
推荐指数
1
解决办法
324
查看次数

c,结构后面的函数定义

  675  * Check the validity of an ACL for a file.
  676  */
  677 int
  678 ufs_aclcheck(ap)
  679         struct vop_aclcheck_args /* {
  680                 struct vnode *vp;
  681                 acl_type_t type;
  682                 struct acl *aclp;
  683                 struct ucred *cred;
  684                 struct thread *td;
  685         } */ *ap;
  686 {
  687 
  688         if ((ap->a_vp->v_mount->mnt_flag & (MNT_ACLS | MNT_NFS4ACLS)) == 0)
  689                 return (EOPNOTSUPP);
  690 
  691         if (ap->a_type == ACL_TYPE_NFS4)
  692                 return (ufs_aclcheck_nfs4(ap));
  693 
  694         return (ufs_aclcheck_posix1e(ap));
  695 }
  696 
  697 #endif /* !UFS_ACL …
Run Code Online (Sandbox Code Playgroud)

c freebsd

3
推荐指数
1
解决办法
79
查看次数

scala switch case逻辑,其他日期在这段代码中意味着什么

days match {
  case firstDay :: otherDays =>
    println("The first day of the week is: " + firstDay)
  case List() =>
    println("There don't seem to be any week days.")
}
Run Code Online (Sandbox Code Playgroud)

在这段代码中,"otherDays"是什么意思?如何理解这种开关案例逻辑?

谢谢

scala

3
推荐指数
1
解决办法
104
查看次数