小编Lin*_* Ma的帖子

重载方法需要Scala中的结果类型吗?

这是我的代码,我实际上不需要任何返回值和类型,并想知道如何处理此错误?

"重载方法需要结果类型"的错误就在这一行 foo (start, end, 14)

object HelloWorld {

  def foo(start: String, end: String) = {
     foo (start, end, 14)
  }

  def foo(start: String, end: String, id: Int) = {
     println("Hello, world!")
  }

  def main(args: Array[String]): Unit = {

    foo("hello", "scala")
  }
}
Run Code Online (Sandbox Code Playgroud)

更正后的代码版本,

object HelloWorld {

  def foo(start: String, end: String): Unit = {
     foo (start, end, 14)
  }

  def foo(start: String, end: String, id: Int): Unit = {
     println("Hello, world!")
  }

  def main(args: Array[String]): Unit = {

    foo("hello", …
Run Code Online (Sandbox Code Playgroud)

scala

2
推荐指数
1
解决办法
1650
查看次数

提交Java并发框架的方法

新提交Java并发框架的方法.想知道在我调用submit或者调用get时线程是否被执行了?研究了Oracle官方文档,但找不到太多信息.谢谢.

我指的是下面的示例,

http://www.vogella.com/tutorials/JavaConcurrency/article.html

package de.vogella.concurrency.callables;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class CallableFutures {
  private static final int NTHREDS = 10;

  public static void main(String[] args) {

    ExecutorService executor = Executors.newFixedThreadPool(NTHREDS);
    List<Future<Long>> list = new ArrayList<Future<Long>>();
    for (int i = 0; i < 20000; i++) {
      Callable<Long> worker = new MyCallable();
      Future<Long> submit = executor.submit(worker);
      list.add(submit);
    }
    long sum = 0;
    System.out.println(list.size());
    // now retrieve the result
    for (Future<Long> future : …
Run Code Online (Sandbox Code Playgroud)

java multithreading java.util.concurrent

2
推荐指数
1
解决办法
260
查看次数

Python中的type(4)== type(int)是False?

我想type(4) == type(int),它会返回False,但print type(4)回报<type 'int'>,所以4明显int.

困惑为什么第一个语句返回False而不是True

python types integer python-2.7

2
推荐指数
1
解决办法
123
查看次数

geom_text 适用于 R 中的直方图?

想知道是否geom_text适用hist?尝试了以下代码,似乎没有效果。在为每个直方图桶绘制每个条时,我只想显示标签(属于特定直方图桶的元素数量)。任何解决方案表示赞赏。谢谢。

p <- hist(df$foo,
          main="title",xlab="foo")
p + geom_text()
Run Code Online (Sandbox Code Playgroud)

编辑 1,试过geom_bar,这是我的代码,它似乎工作不正常,因为我希望每个条上都标有一个数字。在图中,它只显示 2.5、5、7.5 和 10,我希望为每个条显示 1、2、3、...、9、10。

g <- ggplot(df, aes(df$foo))
g + geom_bar()
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

问候, 林

r histogram ggplot2

2
推荐指数
1
解决办法
2850
查看次数

链接列表输出在Python 2.7中不是预期的

实现一个链表,我希望输出0, -1, -2, -3, ... etc.,但是-98, -98, -98, -98, ... etc.,我想知道我的代码有什么问题?谢谢.

MAXSIZE = 100
freeListHead = None

class StackNode:
    def __init__(self, value, nextNode):
        self.value = value
        self.nextNode = nextNode

if __name__ == "__main__":
    # initialization for nodes and link them to be a free list
    nodes=[StackNode(-1, None)] * MAXSIZE
    freeListHead = nodes[0]
    for i in range(0, len(nodes)-1):
        nodes[i].nextNode = nodes[i+1]
        nodes[i].value = -i
    for node in nodes:
        # output -98, -98, -98, -98, ... etc.
        # …
Run Code Online (Sandbox Code Playgroud)

python python-2.7

2
推荐指数
1
解决办法
63
查看次数

在Java Enum中实例化

为了免费序列化(Effective Java Edition 2,Item 3),在Enum中定义INSTANCE是一个很好的做法.如果有人能够解释它意味着什么,它会很棒.

在Java中使用Enum作为单例的最佳方法是什么?

林先生,提前谢谢

java enums serialization

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

如何在grep期间显示文件名

这是我当前的代码,我也更喜欢显示匹配的文件名(如果文件的内容与 grep 匹配),任何解决方案都会受到赞赏。

for file in *.py;
do grep -n --color 'main' $file;
done
Run Code Online (Sandbox Code Playgroud)

顺便说一句,我使用的是 Linux/OS X。

提前致谢,林

linux macos grep

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

递归计算pow(x,n)比蛮力更好吗?

我看到人们实施时pow(x,n),他们总是使用下面的类似解决方案.我的困惑是,下面的解决方案比较强力多倍x n次的优势是什么?

public class Solution {
    public double pow(double x, int n) {
        if(n == 0)
            return 1;
        if(n<0){
            n = -n;
            x = 1/x;
        }
        return (n%2 == 0) ? pow(x*x, n/2) : x*pow(x*x, n/2);
    }
}
Run Code Online (Sandbox Code Playgroud)

java algorithm

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

关于hadoop fs测试命令输出

我在命令下运行,尝试使用文件名存在或文件名不存在,但它们均未从控制台获得任何输出。我希望如果文件存在,命令应该返回零?

http://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/FileSystemShell.html#test

hadoop fs -test -e filename
Run Code Online (Sandbox Code Playgroud)

hadoop

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

Java 中 BigInteger 的 log2

想知道有没有log_2直接计算的API ?这是我当前的代码,我将其转换log_2(N)log_e(N)/log_e(2).

BTW,好像对于普通的Java Double类型,有没有log_2(double_value)直接计算的方法?

我的 Java 代码

BigInteger x = BigInteger.valueOf(16);
BigInteger y = BigInteger.valueOf((long)(Math.log(x.longValue()) / Math.log(2)));
System.out.println(y.doubleValue()); // return 4.0 as expected
Run Code Online (Sandbox Code Playgroud)

java

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