Java Reference
In-Depth Information
ce to the
work
method. We then print this out to show that it has a valid structure as a Java
object.
Example 9-4. ReferencesDemo3.java
public
public class
class
ReferencesDemo3
ReferencesDemo3
{
interface
interface
FunInterface
FunInterface
{
void
void
process
(
int
int
i
,
String j
,
char
char
c
,
double
double
d
);
}
public
public static
static
void
void
work
(
int
int
i
,
String j
,
char
char
c
,
double
double
d
){
System
.
out
.
println
(
"Moo"
);
}
public
public static
void
main
(
String
[]
args
) {
FunInterface sample
=
ReferencesDemo3:
:
work
;
System
.
out
.
println
(
"My process method is "
+
sample
);
static
void
}
}
This generates the following output:
My process method is functional.ReferencesDemo3$$Lambda$1/713338599@4a574795
The
Lambda$1
in the name is structurally similar to the β$1β used in anonymous inner
classes.
The fourth way, what Oracle documentation calls βan Instance Method of an Arbitrary Ob-
ject of a Particular Type,β may be the most esoteric thing in all of Java 8. It allows you to de-
clare a reference to an instance method, but without specifying which instance. Because there
is no particualr instance in mind, you again use the class name. This means you can use it
Because the names in this array can begin with a lowercase letter, we want to sort them using
the
String
method
compareToIgnoreCase()
, which nicely ignores case differences for us.
Because I want to show the sorting several different ways, I set up two array referencess, the
original, unsorted one, and a working one that is re-created, sorted, and printed using a
simple dump routine, which isn't shown (it's just a
for
loop printing the strings from the
passed array).
Example 9-5. ReferencesDemo4.java