#include <iostream>
struct Java_boolean
{
explicit constexpr Java_boolean( bool b = false ) : value(b) {}
using Java_bool_t = void (Java_boolean::*)() const ;
operator Java_bool_t() const { return value ? &Java_boolean::not_integral : nullptr ; }
int to_int() const { return value ; }
bool operator== ( Java_boolean that ) const { return value == that.value ; }
bool operator!= ( Java_boolean that ) const { return value != that.value ; }
Java_boolean operator! () const { return Java_boolean { !value } ; }
private:
bool value ;
void not_integral() const {}
template < typename STREAM > inline friend
STREAM& operator << ( STREAM& stm, Java_boolean b )
{ return stm << "Java_" << ( b.value ? "true" : "false" ) ; }
};
constexpr Java_boolean Java_true { true } ;
constexpr Java_boolean Java_false { false } ;
int main()
{
Java_boolean flag { Java_true } ;
if( flag ) std::cout << "ok\n" ;
if( flag == Java_true ) std::cout << "ok\n" ;
std::cout << flag << '\n' ;
int i = flag.to_int() ; // fine
//int j = flag ; // error
flag = Java_boolean(i) ; // fine
// flag = i ; // error
}