In C#, you can define small pieces of code called delegates anonymously (even though they are nothing more than syntactic sugar). So, or example, I can do this:
public string DoSomething(Func<string, string> someDelegate)
{
// Do something involving someDelegate(string s)
}
DoSomething(delegate(string s){ return s += "asd"; });
DoSomething(delegate(string s){ return s.Reverse(); });
Is it possible to pass code like this in Java? I'm using the processing framework, which has a quite old version of Java (it doesn't have generics).