Java: Long result = -1: cannot convert from int to long

后端 未结 7 805
你的背包
你的背包 2020-12-03 19:39

I\'m using eclipse java ee to perform java programming.

I had the following line of code in one of my functions:

Long result = -1;

7条回答
  •  不思量自难忘°
    2020-12-03 20:14

    First of all, check you Java version: run "java -version" from command line.

    In Java version prior to 1.5, the correct syntax is:

    Long result = new Long(1L);

    In java >1.5 it's done automatically. It's called "autoboxing".

    The uppercase "L" tells Java that the number should be interpreted as long.

提交回复
热议问题