Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. What is the size of a boolean variable in Java? Ask Question. Asked 12 years, 10 months ago.
Active 4 years ago. Viewed k times. DonX DonX The same is asked here: stackoverflow. Active Oldest Votes. Community Bot 1 1 1 silver badge. Jon Skeet Jon Skeet 1. It just gives an order to the JVM to run the garbage collection, but it doesn't mean that the collector actually cleaned something.
An object is unused if the program holds no more references to it. So in your test I would explicitly drop the reference by setting LotsOfBooleans to null before running gc ; OR just run main once with boolean, once with int then compare the numbers. RandaSbeity Or even better: make sure you preserve both references and calculate the memory difference.
Which is exactly what happens here. Is there any question Jon Skeet can not answer? Show 1 more comment. It's virtual machine dependent. Sotirios Delimanolis k 54 54 gold badges silver badges bronze badges. Warrior Warrior Care to point to some docs? I find it hard to believe that the size of a boolean is machine dependant. We just launched W3Schools videos. Get certified by completing a course today! If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:.
Example System. The Boolean value of an expression is the basis for all Java comparisons and conditions. You will learn more about conditions in the next chapter. Report Error. Because the user variable is set to true then!
If user was set to false then! Think of it like this: if something is NOT true then what is it? Or if it's NOT false then what? Back to the Java Contents Page. NET Web Design.
0コメント