相关疑难解决方法(0)

为什么Java API使用int而不是short或byte?

为什么Java API会使用int,何时short甚至byte是足够的?

示例:DAY_OF_WEEK类中的字段Calendar使用int.

如果差异太小,那么为什么存在这些数据类型(short,int)?

java optimization types java-api

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

Java中的转换和简短参数问题

我想了解以下代码:

public class A {
   private void doTask()  {    
      doInt(99);
   }   

   public short doInt(short s)  { 
      return 100;
   }   
}
Run Code Online (Sandbox Code Playgroud)

代码在"doInt(99)"行上给出编译器错误.

The method doInt(short) in the type A is not applicable for the arguments (int)
Run Code Online (Sandbox Code Playgroud)

有人可以解释为什么它会给我错误.

java

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

JAVA 无法从 int 转换为 short

嗨,我是新来的,这是我的第一个问题:我有一个带有简单算术运算符的代码。但它不会工作:

int a = 10;
short premennaTypuShort = (short)a;     /*retyped variable a into short type and entered into new variable*/
premennaTypuShort = premennaTypuShort - 7;
/*now i am trying to decrease the number but eclipse wrote that cannot convert from int to short.*/
Run Code Online (Sandbox Code Playgroud)

我正在尝试减少指定为 short 的数字,但 eclipse 写的无法从 int 转换为 short。我不明白为什么。那么问题出在哪里呢?我该如何修复这个错误?

java int short

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

Java:必须转换为短,不能使用简写“S”

我正在尝试调用一个需要短值的函数。以下作品:

i.setDamage((short) 10);
Run Code Online (Sandbox Code Playgroud)

然而,这并不:

i.setDamage(10S);
Run Code Online (Sandbox Code Playgroud)

根据我正在使用的 IDE,这应该可以工作。为什么不呢?我正在使用 Maven 和 Java 7。

java casting short java-7

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

标签 统计

java ×4

short ×2

casting ×1

int ×1

java-7 ×1

java-api ×1

optimization ×1

types ×1