-2

How would you port this c# code over to Java?

public Hash(object defaultValue)
: this()
{
_defaultValue = defaultValue;
}

public Hash(Func<Hash, string, object> lambda)
: this()
{
_lambda = lambda;
}

public Hash()
{
_nestedDictionary = new Dictionary<string, object>(Template.NamingConvention.StringComparer);
}
Blankman
  • 259,732
  • 324
  • 769
  • 1,199

1 Answers1

2

The closest thing that Java has to delegates is a single method interface using an anonymous inner class. The Callable interface is somewhat similar to Func.

See these questions:

Equivalent of C# anonymous methods in Java?

Java's equivalents of Func and Action

Community
  • 1
  • 1
Deco
  • 3,261
  • 17
  • 25