blog

네 가지 기능적 인터페이스

함수 술어 소비자 공급업체 요약...

Oct 29, 2025 · 2 min. read
シェア

Function기능적 인터페이스

public interface Function<T, R> {
 /**
 * Applies this function to the given argument
 * @param t the function argument
 * @return the function result
 */
 R apply(T t);
}
// 인터페이스가 작동하는 한 람다 표현식을 사용할 수 있습니다.
public class test1 {
 public static void main(String[] args) {
 Function function = new Function<String, String>() {
 @Override
 public String apply(String str) {
 return str;
 }
 };
 //lambda 
 Function<String,String> function = (str)->{return str;}; 
 System.out.println(function.apply("asdf"));
 }
}

술어 판단 인터페이스

public interface Predicate<T> {
 /**
 * Evaluates this predicate on the given argument.
 *
 * @param t the input argument
 * @return {@code true} if the input argument matches the predicate,
 * otherwise {@code false}
 */
 boolean test(T t);
}
public class test2 {
 public static void main(String[] args) {
 Predicate<String> predicate = new Predicate<String>() {
 @Override
 public boolean test(String s) {
 return s.isEmpty();
 }
 };
 Predicate<String> predicate = (string)->{
 return string.isEmpty();
 };
 System.out.println(predicate.test("hello")); //false
 }
}

소비자 소비자 인터페이스

public interface Consumer<T> {
 /**
 * Performs this operation on the given argument.
 * @param t the input argument
 */
 void accept(T t);
}
public class test3 {
 public static void main(String[] args) {
 Consumer<String> consumer = new Consumer<String>() {
 @Override
 public void accept(String s) {
 System.out.println(s);
 }
 };
 Consumer<String> consumer = (string)->{
 System.out.println(string);
 };
 consumer.accept("hello");
 }
}

공급업체 공급 유형 인터페이스

public interface Supplier<T> {
 /**
 * Gets a result.
 * @return a result
 */
 T get();
}
public class test4 {
 public static void main(String[] args) {
 Supplier<String> supplier = new Supplier<String>() {
 @Override
 public String get() {
 return "1024";
 }
 };
 Supplier<String> supplier = ()->{
 return "1024";
 };
 System.out.println(supplier.get());
 }
}

요약

public class ConsumerPractice {
 public static void main(String[] args) {
 Consumer<String> a=b-> System.out.println(b);
 a.accept("hello");
 Function<Integer,String> ad=b->b.toString();
 System.out.println(ad.apply(11));
 Predicate<String> ac=b->b.isEmpty();
 System.out.println(ac.test("hello"));
 Supplier<String> ae= ()-> "a";
 System.out.println(ae.get());
 }
}
Read next

Redis, 일반적인 스토리지 유형 및 비즈니스에서 선택하는 방법

Redis의 일반적인 저장소 유형 1. 문자열 Redis의 문자열은 문자열 값을 저장하고 검색하는 데 사용되는 기본 데이터 유형입니다. 사용 사례: 사용자 이름, 이메일 주소, 페이지 카운터와 같은 텍스트나 숫자를 저장하는 데 적합합니다. 문자열

Oct 29, 2025 · 6 min read

제품 통합 계획 템플릿

Oct 29, 2025 · 1 min read

Typora 소책자 테마

Oct 29, 2025 · 1 min read

9. 에코 수

Oct 29, 2025 · 2 min read

CSS에서 플로팅

Oct 29, 2025 · 3 min read