chattsm
chattsm

Reputation: 4739

How is this a valid Java method invocation?

I've just been reading Marko Rodriguez's excellent blog post about different types of databases. Whilst reading I noticed some syntax...

// put data
db.put('marko');
db.put(31);
db.put(true);
// get data
Iterator results = db.get();
Iterator filteredResults = db.get{it.startsWith('ma')};

...which I presumed was a snippet of Java, but I've never seen a method invoked using curly braces like this before - db.get{it.startsWith('ma')}.

Any details/thoughts on this would be appreciated!

Upvotes: 1

Views: 319

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1502985

That looks like it's probably Groovy (using closures) rather than Java. Note that it also uses 'marko' which isn't valid Java. (Java uses single quotes for character literals, not string literals.)

That would also fit with the author's involvement in Gremlin, which is written in Groovy.

Upvotes: 10

Related Questions