Abhiroop Sarkar
Abhiroop Sarkar

Reputation: 2311

Guava Function in interfaces

I am going through an old code base of Java 6 and I see this in one of the interfaces

public static Function<Model, Map<? extends Class<? extends Feature>, Map<String, String>>> getRequiredFeatures = new Function<Model, Map<? extends Class<? extends Feature>, Map<String, String>>>() 
{
  @Override
  public Map<? extends Class<? extends Feature>, Map<String, String>> apply(final Model input) 
  {
     return input.getRequiredFeatures();
  }
};

Besides lots of Generic types, what I didnt understand is what is exactly being done here. Arent we just allowed to declared method signatures in interfaces? SO how does this work. I also see a lot of this in the code which also I dont understand:

public static Function<Model, Set<Model>> unwrap = function(FuncitoGuava.<Model, Set<Model>>functionFor(callsTo(Model.class).unwrap()));

This might be a noob question as I am pretty new to FP and Guava in general. So please go easy on this question. Thanks.

Upvotes: 1

Views: 431

Answers (1)

ifloop
ifloop

Reputation: 8386

The first code snippet is not a method declaration. It is a field declaration.

The field is of the type com.google.commons.base.Function<F, T> which is an interface and therefore you need to implement all the methods of this interface (which is here in fact public Map<...> apply(final Model input))

Upvotes: 2

Related Questions