相关疑难解决方法(0)

设置短值Java

我在J2ME中编写了一些代码.我有一个方法课setTableId(Short tableId).现在当我尝试编写setTableId(100)它时会出现编译时错误.如何在不声明另一个短变量的情况下设置短值?

设置Long值时,我可以使用setLongValue(100L)它,它的工作原理.那么,L这里的含义是什么,Short价值的特征是什么?

谢谢

java literals primitive-types

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

Eclipse bug?什么时候短暂不短?

这是Eclipse中的错误吗?

声明一个短变量时,编译器将整数文字视为short.

// This works
short five = 5;
Run Code Online (Sandbox Code Playgroud)

但是,当将整数文字作为短参数传递时,它不会执行相同的操作,而是生成编译错误:

// The method aMethod(short) in the type Test is not applicable for 
// the arguments (int)
aMethod(5); 
Run Code Online (Sandbox Code Playgroud)

它清楚地知道整数文字何时超出短期范围:

// Type mismatch: cannot convert from int to short
    short notShort = 655254
Run Code Online (Sandbox Code Playgroud)

-

class Test {
    void aMethod(short shortParameter) {
    }

    public static void main(String[] args) {
        // The method aMethod(short) in the type Test is not applicable for 
        // the arguments (int)
        aMethod(5); 

      // the integer literal has to be …
Run Code Online (Sandbox Code Playgroud)

java eclipse

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

标签 统计

java ×2

eclipse ×1

literals ×1

primitive-types ×1