Why does the compiler not give an error for this addition operation?

This question already has an answer here: Why don't Java's +=, -=, *=, /= compound assignment operators require casting? 11 answers The answer is provided by JLS 15.26.2: For example, the following code is correct: short x = 3; x += 4.6; and results in x having the value 7 because it is equivalent to: short x = 3; x = (short)(x + 4.6); So, as you can see, the latest cas

为什么编译器不为这个加法操作提供一个错误?

这个问题在这里已经有了答案: 为什么Java的+ =, - =,* =,/ =复合赋值操作符需要转换? 11个答案 答案由JLS 15.26.2提供: 例如,以下代码是正确的: short x = 3; x += 4.6; 并导致x的值为7,因为它相当于: short x = 3; x = (short)(x + 4.6); 所以,正如你所看到的,最新的情况实际上是有效的,因为添加赋值(和任何其他操作符赋值一样)对左手类型执行隐式转换(在你的情况中a是一个byte )。 扩展

Does Java support default parameter values?

I came across some Java code that had the following structure: public MyParameterizedFunction(String param1, int param2) { this(param1, param2, false); } public MyParameterizedFunction(String param1, int param2, boolean param3) { //use all three parameters here } I know that in C++ I can assign a parameter a default value. For example: void MyParameterizedFunction(String param1, int

Java是否支持默认参数值?

我遇到了一些具有以下结构的Java代码: public MyParameterizedFunction(String param1, int param2) { this(param1, param2, false); } public MyParameterizedFunction(String param1, int param2, boolean param3) { //use all three parameters here } 我知道在C ++中,我可以为参数分配一个默认值。 例如: void MyParameterizedFunction(String param1, int param2, bool param3=false); Java是否支持这种语

Viewer extremely slow as webstartable

Just tried to add some swingx-ws components to the overall swinglabs demos - and noticed that a simple JXMapKit/-Viewer is orders of magnitude slower to load the tiles in the webstartable compared to loading locally. Rather lost on where I should start looking (ui updates seem to be on the EDT, though might need a closer look): anybody else experiencing the different loading times? any gues

浏览器非常慢,因为webstartable

试图将一些swingx-ws组件添加到整个swinglabs演示中,并注意到与在本地加载相比,简单的JXMapKit / -Viewer在加载webstartable中的图块时速度要慢几个数量级。 相反,我应该开始寻找的东西丢失(更新似乎在美国东部时间,尽管可能需要仔细观察): 任何其他人经历不同的加载时间? 任何猜测可能是什么原因? 如何调试webstartable? 代码非常简单(要在本地运行,您需要使用swingx和swingx-ws: public class WSDemo {

javap and generics' type erasure

I am reading Herbert Schilds about type erasure in generics in java. Supposedly running javap on a class should give me the bytecode information about public, package protected and protected fields and methods after type erasure. However, I wrote the following class: class Ambiguity<T, V extends String>{ T ob1; V ob2; void set(T o){ ob1 = o; } void set(V

javap和泛型'类型擦除

我正在阅读Herbert Schilds关于java中泛型的擦除类型。 假设在一个类上运行javap应该给我关于在类型擦除之后的公共,包保护和保护字段和方法的字节码信息。 不过,我写了下列课程: class Ambiguity<T, V extends String>{ T ob1; V ob2; void set(T o){ ob1 = o; } void set(V o){ ob2 = o; } } 并在生成的类文件上运行javap并获得以下输出 从“Test.java”编译 class

Weak references and `OutOfMemoryError`s

I have a SoundManager class for easy sound management. Essentially: public class SoundManager { public static class Sound { private Clip clip; // for internal use public void stop() {...} public void start() {...} public void volume(float) {...} // etc. } public Sound get(String filename) { // Gets a Sound for the given clip }

弱引用和`OutOfMemoryError`s

我有一个SoundManager类,可以轻松进行声音管理。 主要有: public class SoundManager { public static class Sound { private Clip clip; // for internal use public void stop() {...} public void start() {...} public void volume(float) {...} // etc. } public Sound get(String filename) { // Gets a Sound for the given clip } // moar s

MongoDB/Java SDK: Query elements with a value in array

I am very new to MongoDB and its Java... SDK? Api? I have a very simple question, but I haven't been able to find a satisfactory answer. Let's say I have a collection of instances that are like: { "_id": { "$oid": "5156171e5d451c136236e738" }, "_types": [ "Sample" ], "last_z": { "$date": "2012-12-30T09:12:12.250Z" }, "last": {

MongoDB / Java SDK:使用数组中的值查询元素

我对MongoDB及其Java ... SDK非常新颖? API? 我有一个非常简单的问题,但我一直未能找到满意的答案。 假设我有一个如下所示的实例集合: { "_id": { "$oid": "5156171e5d451c136236e738" }, "_types": [ "Sample" ], "last_z": { "$date": "2012-12-30T09:12:12.250Z" }, "last": { "$date": "2012-12-30T04:12:12.250Z" }, "section": "5156171e5d4

java bitwise left shift

This question already has an answer here: What are bitwise shift (bit-shift) operators and how do they work? 8 answers left shift by one bit moves all the bits in the value one bit position to the left. The position that gets free at the right side is filled with bit 0, the bit that was farmost left is lost. This is the same effect as multiplying the value by 2. Example (using just 8 bi

java按位左移

这个问题在这里已经有了答案: 什么是位移(位移)操作符,它们是如何工作的? 8个答案 向左移一位将值的一位位置中的所有位移动到左边。 右侧空闲的位置填充0位,最左侧的位丢失。 这与将值乘以2相同的效果。 示例(为简单起见,仅使用8位): original value 10010011 after shift left 00100110 如果向左移n位,则重复n次(如果n小于字长)。 对于大于字长移位n的字长。

Why doesn't bit shift work for

This question already has an answer here: What are bitwise shift (bit-shift) operators and how do they work? 8 answers This is because of sign extension. -1 is represented by the bit sequence containing only 1s. Using the right shift with sign extension therefore always yields the sequence with all bits 1, ie -1 , regardless of the second operand of the bitshift.

为什么不移位工作

这个问题在这里已经有了答案: 什么是位移(位移)操作符,它们是如何工作的? 8个答案 这是因为符号扩展。 -1由仅包含1的比特序列表示。 因此,使用带符号扩展的右移,无论bitshift的第二个操作数如何,都会产生所有位为1的序列,即-1 。

Dont understand: (x>>24)&0xff

This question already has an answer here: What are bitwise shift (bit-shift) operators and how do they work? 8 answers Those are bitwise operations. p>>24 shifts first byte in p int 24 places to the right and &0xff performs bitwise and with shifted number and hexadecimal number ff(decimal 255). avg << 16 shifts first byte in avg int 16places to the left. And | performs bi

不明白:(x >> 24)&0xff

这个问题在这里已经有了答案: 什么是位移(位移)操作符,它们是如何工作的? 8个答案 这些都是按位操作。 p >> 24将p int中的第一个字节移位到右边的24个位置,并且&0xff执行按位并移位的数字和十六进制数ff(十进制255)。 avg << 16将avg int 16位的第一个字节移到左边。 和| 执行按位或其他值。 这些就是所谓的位掩码。 搜索术语按位操作和位掩码以获取更多信息。 希望我帮助:)

What happening here '>>>' operator in java?

This question already has an answer here: What are bitwise shift (bit-shift) operators and how do they work? 8 answers >>> is the unsigned right shift operator. Since a is 60 and 60 is 111100 in binary, when you shift right twice you get 1111 which is 15. >>> is the logical (or unsigned) right shift operator. lets x= 10000000 00000000 00000000 01100000 x >>> 4

java中发生了什么'>>>'运算符?

这个问题在这里已经有了答案: 什么是位移(位移)操作符,它们是如何工作的? 8个答案 >>>是无符号的右移运算符。 由于a是60和60是111100二进制,所以当你向右移两次时,你得到1111这是15。 >>> is the logical (or unsigned) right shift operator. 让x= 10000000 00000000 00000000 01100000 x >>> 4然后x = 00001000 00000000 00000000 00000110 你可以看到最右边的符号位也正在向右