superpackage com.foo {
member package com.foo.api, com.foo.model, com.foo.util
export com.foo.api;
}
// MOUDLE_INF/METADATA.module
name=com.wombat.webservice
extensible-metadata=[@Version("1.0")]
members=[com.wombat.webservice.MainApp,
com.wombat.webservice.PrivateClassA,
com.wombat.webservice.PrivateInterfaceB]
imports=[ImportModule(org.foo.xml, @VersionConstraint("1.3.0")),
ImportModule(org.foo.soap, @VersionConstraint("2.0.0+"))]
class-exports=[com.wombat.webservice.MainApp]
class NewCollection<class E> extends Collection<E> {
...
}
class NewList<class E> extends NewCollection<E>, List<E> {
...
}
Map<@NonNull String, @NonEmpty List<@Readonly Document>> files;
myString = (@NonNull String) myObject;
boolean isNonNull = myString intanceof @NonNull String;
@ReadOnly class RoClass {
public RoClass() @ReadOnly {} // readonly constructor
public RoClass(String s) {} // "mutable" constructor
String x; // this-mutable resolves as readonly
static String sx; // readonly
public void testConstructors() {
RoClass a = new RoClass(); // error
@ReadOnly RoClass b = new RoClass();
a = new RoClass(""); // error
b = new RoClass("");
}
public void testFieldsPseudoMutable() {
@Mutable String a = "a";
a = x; // error
a = sx; // error
sx = x; // error
x = sx; // error
}
public void testFieldsReadOnly() @ReadOnly {
@Mutable String a = "a";
a = x; // error
a = sx; // error
sx = x; // error
x = sx; // error
}
}
RoClass.java:12: cannot assign a ReadOnly expression to a Mutable variable
RoClass.java:14: cannot assign a ReadOnly expression to a Mutable variable
RoClass.java:20: cannot assign a ReadOnly expression to a Mutable variable
RoClass.java:21: cannot assign a ReadOnly expression to a Mutable variable
RoClass.java:22: a field of a ReadOnly object is not assignable
RoClass.java:23: a field of a ReadOnly object is not assignable
RoClass.java:28: cannot assign a ReadOnly expression to a Mutable variable
RoClass.java:29: cannot assign a ReadOnly expression to a Mutable variable
RoClass.java:30: a field of a ReadOnly object is not assignable
RoClass.java:31: a field of a ReadOnly object is not assignable
public class FileCopier {
public static void main(String[] args) throws IOException {
if (args.length != 2) {
System.err.println("Usage: java FileCopier infile outfile");
return;
}
PathReference source = PathReference.from(args[0]);
PathReference target = PathReference.from(args[1]);
int flags = CopyFlag.COPY_ATTRIBUTES | CopyFlag.REPLACE_EXISTING;
source.copyTo(target, flags);
}
}
PathReference ref = PathReference.from("foo.txt");
PosixFileAttributeView view = ref.newFileAttributeView(PosixFileAttributeView.class);
PosixFileAttributes attrs = view.readAttributes();
// prints "-rw-r--r-- alice bandits"
System.out.format("%s\t%s\t%s%n",
PosixFilePermission.toString(perms),
attrs.getOwner(),
attrs.getGroup());
// deny others
perms &= ~OTHERS_READ & ~OTHERS_WRITE & ~OTHERS_EXECUTE;
view.updatePermissions(perms);
// change group
UserPrincipal cops = view.lookupPrincipalByGroupName("cops");
view.updateOwners(null, cops);
ParallelArray<Student> students = new ParallelArray<Student>(fjPool, data);
double bestGpa = students.withFilter(isSenior)
.withMapping(selectGpa)
.max();
public class Student {
String name;
int graduationYear;
double gpa;
}
static final Ops.Predicate<Student> isSenior = new Ops.Predicate<Student>() {
public boolean op(Student s) {
return s.graduationYear == Student.THIS_YEAR;
}
};
static final Ops.ObjectToDouble<Student> selectGpa = new Ops.ObjectToDouble<Student>() {
public double op(Student student) {
return student.gpa;
}
};
BigInteger low = BigInteger.ONE;
BigInteger high = BigInteger.ONE;
for (int i = 0; i < 500; i++) {
System.out.print(low);
BigInteger temp = high;
high = high.add(low);
low = temp;
};
BigInteger low = 1;
BigInteger high = 1;
for (int i = 0; i < 500; i++) {
System.out.print(low);
BigInteger temp = high;
high = high + low;
low = temp;
};
List content = new LinkedList(10);
content.add(0, "Fred");
content.add(1, "Barney");
String name = content.get(0);
List content = new LinkedList(10);
content[0] = "Fred";
content[1] = "Barney";
String name = content[0];
public class Point {
property double x;
property double y;
}
Point p = new Point(1, 2);
System.out.println(p.x + " " + p.y);
Point p = new Point();
p.setX(56);
p.setY(87);
int z = p.getX();
Point p = new Point();
p->X = 56; // 문법이 C에서 포인터를 사용하는 것 같습니다;
p->y = 87;
int z = p->X;
package java.xml;
abstract class DataCoder {
String encode(Object o);
String encode(Object o, String type);
<T>T decode(String data, Class<T> c);
<T>T decode(String data, Class<T> c, String type);
boolean supports(Class<?> c);
boolean supports(Class<?> c, String type);
static final DataCoder JAVA;
static final DataCoder XSD;
}
void addReviewer(XML feature, String reviewer, Timestamp time) {
DataCoder dc = DataCoder.XSD;
feature.add(<reviewed>
<who>{ reviewer }</who>
<when>{ dc.encode(time) }</when>
</reviewed>);
}