Clojure immutable collections for Java env

(Include clojure.jar in your lib path)

List list = new PersistentList("t1");
try {
	list.add("t2");
} catch (UnsupportedOperationException e) {
	System.out.println("It seems that this operation is not supported.");
}
System.out.println("List size: " + list.size());

Map map = new PersistentArrayMap(new Object[]{"key1", "value1"});
try {
	map.put("key2", "value2");
} catch (UnsupportedOperationException e) {
	System.out.println("It seems that this operation is not supported.");
}
System.out.println("Map size: " + map.size());

This can be used as an alternative for
java.util.Collections.unmodifiableList(…)

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.