There are several methods that count the number of consonants in a word by a given parameter. Methods differ only in the type of argument they take:
public int countPhonotype(Consonant.Place place) { int count = 0; for(Consonant cons : this.transcription) { if (cons.getPlace().equals(place)) { count++; } } return count; } public int countPhonotype(Consonant.Manner manner) { int count = 0; for(Consonant cons : this.transcription) { if (cons.getManner().equals(manner)) { count++; } } return count; }
I would like to take the common part into a separate method, but I cannot find a solution for how to pass the method there. I tried to understand the links to the methods, but the working version failed. I would be grateful for the help.
PS: there are actually more than two methods, so I would not like to “leave it as it is”.
Class::method
, through functional interfaces, through theMethod
class, through theCallable
classCallable
or throughLambda Expressions
. - And