Data type mappings

LotusScript® provides mapping for Java basic data types and Java reference types.

Basic data types

LotusScript® data type

Is mapped to Java data type

Byte

byte

Boolean

boolean

Integer

short

Long

int

String

These three Java data types map to a LotusScript® string:

  • Java char (maps to a LotusScript® String of length 1)
  • Java char array
  • java.lang.String

From LotusScript® to Java, the mapping depends on what the Java code expects as a type. See the example in the String Mapping example.

Single

float

Double

double

long

Which data type is used depends on what the Java code expects as a type.

A Variant should map to whatever data type it contains.

Note: The Java byte type is signed (range -128 to +127), but the LotusScript® Byte type is unsigned (range 0 to +255).

Java byte values of -128 to -1 map to LotusScript® Byte values of +128 to +255. Java byte values of 0 to +127 map to the same LotusScript® values, 0 to +127.

Java byte value

LotusScript® Byte value

-128

+128

-127

+129

-126

+130

...

...

-2

+254

-1

+255

0

0

1

1

...

...

+126

+126

+127

+127

Note: You can use the LotusScript® data type in place of the Java data type for Get/Set properties, arguments for Java methods, and return values.

About Java precision and the long data type

The Java long data type range is:

min -2^63 == -9,223,372,036,854,775,808 == approx. -9.22337203685478E+18

max +2^63 - 1 == +9,223,372,036,854,775,807 == approx. +9.22337203685478E+18

However, because of a lack of precision in floating-point types, LS2J supports only a smaller range of approximately:

+- 9,223,372,036,854,770,000 == +- 9.22337203685477E+18

This range varies slightly by platform. LS2J throws an "Expression out of range" error if a LotusScript® value outside these limits is passed to a Java long data type.

Even within the supported range, only 15 digits of precision are available; that is, a Java long data type will map to a predictable integral LotusScript® value only within the range:

+- 1,000,000,000,000,000 == +- 1.0E+15

String mapping example

LSStrings.java:

public class LSStrings
{
	public char    F1;
	public char [] F2;
	public String F3;
	public char    M1(char p)    { return p; }
	public char [] M2(char [] p) { return p; }
	public String M3(String p) { return p; }
}

LSStrings.lss:

Option Public
Uselsx "*javacon"

Dim mySession As JavaSession

Sub Initialize
	Dim myClass As JavaClass, myObject As JavaObject, s1 As String, _
		s2 As String, s3 As String
	s1 = "A"
	s2 = "BC"
	s3 = "DE"
	Set mySession = New JavaSession ("\LSI\test\java;")
	Set myClass = mySession.GetClass("LSStrings;")
	Set myObject = myClass.CreateObject
	myObject.F1 = s1
	myObject.F2 = s2
	myObject.F3 = s3
	MsgBox myObject.F1 & myObject.F2 & myObject.F3 & _
    myObject.M1(s1) & myObject.M2(s2) & myObject.M3(s3)
	' Displays "ABCDEABCDE"
End Sub

Java reference types

The Java reference types have limited support:

  • The JavaObject data type is mapped directly and dynamically into a LotusScript® ADT. You can use a LotusScript® JavaObject in places where a Java object is needed: for example, in Get/Set properties, arguments for JavaMethods, and return values.
  • LotusScript® is only able to handle single dimension arrays of all the primitive types (byte, short, int, long, float, double, Boolean, and char). The Java char[ ] is mapped to the LotusScript® dynamic string type. Notice that the Java/lang/String class is mapped to a LotusScript® ADT. The following statement prints the actual text string out, assuming that myObject has a toString method, which returns a Java/lang/String object:
    		print myObject.toString().toCharArray()

    LS2J dynamically adapts the Java/lang/String class then binds to the toCharArray method. The toCharArray method returns a char[], which is automatically translated into a LotusScript® string.

Processing arguments

You can pass all primitive types and Java objects directly as arguments to JavaMethods. For reference types, LotusScript® does not yet support the call-by-reference semantics. You can pass single dimension arrays into a Java method, but the results are not copied back into the LotusScript® space. LotusScript® also does not yet support passing in arrays of Java objects.

Limitations

Some important limitations include:

  • You can't bring a bitmap into LotusScript® because the Java byte (signed 8-bit) data type is mapped to LotusScript® integer.
  • You can't bring an integer greater than 32 bits into LotusScript® without losing precision because the Java long (64 bit) data type is mapped to LotusScript® Double.

  • You can use only single dimension arrays.
  • There is no call-by-reference semantics for arguments of reference type.