Skip to content

Boolean

memory-agape edited this page Apr 18, 2019 · 4 revisions

PHPJava\Kernel\Types\_Boolean

Introduction

_Boolean class is provided APIs for emulating Java's boolean on PHPJava.

How to use

The class can be pass boolean type into Java if you want. For an example as follows:

  1. Write Java:
class Test 
{
    public static void echoEnabled(boolean isEnabled)
    {
        if (isEnabled) {
            System.out.println("Excellent, This method is enabled.");
            return;
        }
        System.out.println("OMG, This method is disabled.");
    }
}
  1. Compile Java:
$ javac -UTF8 /path/to/Test.java
  1. Call the echoEnabled method as follows:
<?php
use PHPJava\Core\JavaClass;
use PHPJava\Core\Stream\Reader\FileReader;
use PHPJava\Kernel\Types\\_Boolean;

(new JavaClass(new FileReader('/path/to/Test.class')))
    ->getInvoker()
    ->getStatic()
    ->getMethods()
    ->call(
        'echoEnabled',
        new _Boolean(true)
    );
  1. Get the result
$ php /path/to/Test.php
Excellent, This method is enabled.
  1. In pass parameter is false then result is here:
$ php /path/to/Test.php
OMG, This method is disabled.

Provided methods

Name

public function __construct($value)
Introduction

Initiate a boolean type for Java.

Parameters
Name Type Description
$value mixed Specify boolean value

Name

public function getValue()
Introduction

Return real value.

Parameters

No parameter.

Name

public function getTypeNameInJava()
Introduction

Return type name in Java.

Parameters

No parameter.

Name

public function getTypeNameInPHP()
Introduction

Return type name in PHP.

Parameters

No parameter.

Name

public function __toString()
Introduction

Return stringified real value.

Parameters

No parameter.

Clone this wiki locally