Question: the "String::contains" is wrong. but how to express the lambda?

In addition , when I write this in IntelliJ IDEA :

> 
> obj.testPredicate(list, String::contains);
> 
> 
> 

I get the error in "String::contains" : Non-static method cannot be referenced from a static context. but the contains is not static method. I am confused by the tips.

my code as follows:

```
public <T> List<T> testPredicate(List<T> list , Predicate<T> predicate){
    List<T> result = new ArrayList<>();
    for(T t: list){
        if(predicate.test(t)){
            result.add(t);
        }
    }
    return result;
}

```

and this is the caller:

```
@Test
public void testPredicate() throws Exception {
    List<String> listTemp = lambda.testPredicate(list, s -> s.contains("o"));
    System.out.println(listTemp);
}

```

**why the simplest lambda cannot be replace by method reference?** 

and I see the [Using method reference instead of multi argument lambda](https://stackoverflow.com/questions/23139725/using-method-reference-instead-of-multi-argument-lambda).

it says 

> 
> (2) If func is an instance method, then SomeClass::func is a lambda that uses the first argument as the instance, as you thought:
>  (a, b, c) -> a.func(b, c);
> 
> 
> 

there is no defference with my (String a, String b)-> a.contains(b); why method reference did not work?

Answer: 
You can create your own predicates:

```
public class StringPredicates {
  public static Predicate<String> contains(String contained) {
    return s -> s.contains(contained);
  }
}

```

Then you can use them similarly to this:

```
obj.testPredicate(list, StringPredicates.contains("o"));

```

Note, that you don't need method references to use such a construct. As I always say: use the right tool when needed! In this case you have a variable, so it's not advisable to use a method reference.

If you really must use a method reference, you can always write this:

```
public static boolean containsO(String s) {
  return s.contains("o");
}

```

And then use it:

```
obj.testPredicate(list, StringPredicates::containsO);

```
Static re-usable Predicate 

```
    public static Predicate<String> contains(String contained) {
        return s -> s.contains(contained);
    }

```

Test code

```
@Test
    public <T> List<T> testPredicate(List<T> list , Predicate<T> contains){
    return list.stream()
        .filter(contains)
        .collect(Collectors.toList());
    }

```