Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikibooksThe Free Textbook Project
Search

Java Programming/Keywords/boolean

From Wikibooks, open books for an open world
<Java Programming |Keywords

boolean is akeyword which designates thebooleanprimitive type. There are only two possibleboolean values:true andfalse. The default value forboolean fields isfalse.

The following is a declaration of aprivateboolean field namedinitialized, and its use in a method namedsynchronizeConnection.

ExampleCode section 1: Connection synchronization.
privatebooleaninitialized=false;publicvoidsynchronizeConnection(){if(!initialized){connection=connect();initialized=true;}}

The previous code only creates a connection once (at the first method call). Note that there is no automatic conversion between integer types (such asint) toboolean as is possible in some languages likeC. Instead, one must use an equivalent expression such as(i != 0) which evaluates totrue ifi is not zero.

Retrieved from "https://en.wikibooks.org/w/index.php?title=Java_Programming/Keywords/boolean&oldid=3283586"
Category:
Hidden category:

[8]ページ先頭

©2009-2025 Movatter.jp