小编Dhr*_*Pal的帖子

比较传递null int String和Integer构造函数

请考虑以下两个陈述

    Integer integer = new Integer(null);
    String string = new String(null);
Run Code Online (Sandbox Code Playgroud)

第二个给出编译错误说

Cannot resolve constructor `String(null)`
Run Code Online (Sandbox Code Playgroud)

现在Integer和String都有接受的构造函数String.那么字符串如何给出编译错误而不是整数错误.

打电话给第一个电话

  public Integer(String s) throws NumberFormatException {
        this.value = parseInt(s, 10);
    }
Run Code Online (Sandbox Code Playgroud)

所以我期待字符串一也打电话

 public String(String original) {
        this.value = original.value;
        this.hash = original.hash;
    }
Run Code Online (Sandbox Code Playgroud)

我无法理解这是如何发生的,并且编译器被迫在一个而不是其他的编译错误.

java

3
推荐指数
2
解决办法
599
查看次数

提供 png 图像的 Axios 提供损坏的图像

我使用 express 作为中间件 api。一个人点击了我的中间件,它点击了一些第三方 api 并返回结果。它适用于所有其他端点,期望一个 get 端点创建一个 png 并为其提供服务。所以在方法下返回响应

   _execute = R.curry((reqFunction, req, res) => {
        reqFunction(req, res).
        then(r => {
          res.status(r.status).header(r.headers).send(r.data)
        }).
        catch(err => {
          res.status(err.response.status).header(err.headers).send(err.response.data)
        })
      });
Run Code Online (Sandbox Code Playgroud)

reqFunction方法一样

  modelDiagram = (req, res) => {
    const headers = req.headers;
    const modelName = req.params['modelName'];
    const endPoint = this.modelDiagramEndPoint + '/' + modelName;
    return this.httpRequests.get(endPoint, headers);
  }
Run Code Online (Sandbox Code Playgroud)

httpRequests.get方法是

  get = (endPoint, headers) => {
    let options = {
      method: 'GET',
      url: endPoint
    }
    options = this.addHeaders(headers, …
Run Code Online (Sandbox Code Playgroud)

javascript es6-promise ramda.js axios

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

使用按位运算或数字文字初始化值是否更快?

我正在浏览源代码HashMap.我看到了一些 static final int DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16.我想知道为什么他们使用移位操作符的东西.这会加快计算速度吗?所以我寻找byte这三个操作之间的差异:

int DEFAULT_INITIAL_CAPACITY =  0x10;
L0
    LINENUMBER 52 L0
    BIPUSH 16
    ISTORE 1



int DEFAULT_INITIAL_CAPACITY1 =  1 << 4;
  L1
    LINENUMBER 54 L1
    BIPUSH 16
    ISTORE 2

int test = 16;
 L2
    LINENUMBER 56 L2
    BIPUSH 16
    ISTORE 3
Run Code Online (Sandbox Code Playgroud)

这个值如何初始化是否重要?

java hashmap bit-shift bitwise-operators

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