@Target(value=TYPE)
@Retention(value=SOURCE)
public @interface StringPool
Within a defined pool each string constant is defined using the
StringDef
annotation.
This annotation is processed at compile-time and is then discarded by the compiler.
The annotation processor that handles this annotation generates the source
for a class that defines a field of type byte[]
for each of the
string constants. The generated class is named as per the given
name
attribute.
If the export
attribute is set to true
then the
string constant definitions are typically intended to be part of a library.
The generated class is a public
class and for each string constant
definition a field with the following characteristics is generated:
public
byte[]
name
attributevalue
attribute or the value of the
string constant definition's field referenced by the reference
attributepublic
default constructor.
If the export
attribute is set to false
then the
string constant definitions are typically intended to be used within an applet's
package. The generated class is a package-private
class and for
each string constant definition a field with the following characteristics is
generated:
static
) fieldpackage-private
byte[]
name
attributevalue
attribute or the value of the
string constant definition's field referenced by the reference
attributepackage-private
static
method importLibConstants()
with the void
return type that must be invoked prior to accessing
any string constant field defined by reference. This method instantiates all
the string pool classes defining the string constants that are referenced.
Defining string constants that reference other string constants from libaries is a convenience mechanism that allows for an applet developer to use the same coding pattern regardless of whether a string constant is defined in the applet's package or in a library. In both cases, the applet developer can use static field access. If footprint is an issue, an applet developer should directly instantiate string constant pool classes from libraries.
The following example illustrates how to use the annotation to declare string constants local to the declaring application or imported from a library:package com.sun.jcclassic.samples.stringapp; import javacardx.annotations.*;For information on how to invoke a string annotation processor, see Oracle's string annotation processor.@
StringPool(value = {@
StringDef(name = "S1", value = "Hello World!"),@
StringDef(name = "S2", reference = "com.sun.jcclassic.samples.stringlib.LibStrings.Hello") }, name = "AppStrings") public class StringHandlingApp extends Applet { protected StringHandlingApp() { AppStrings.importLibConstants(); // initializes lib constants byte[] x = AppStrings.S1; byte[] y = AppStrings.S2; short l = (short) AppStrings.S1.length; ... } ... }
StringDef
public abstract StringDef[] value
public abstract boolean export
public abstract java.lang.String name
"$$Strings"
to the fully
qualified name of the annotated class or interface.Copyright © 1998, 2015, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms