001 /* 002 * Copyright (C) 2009 The Guava Authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 package com.google.common.util.concurrent; 018 019 import java.util.concurrent.Callable; 020 021 import javax.annotation.Nullable; 022 023 /** 024 * Static utility methods pertaining to the {@link Callable} interface. 025 * 026 * @author Isaac Shum 027 * @since 1 028 */ 029 public final class Callables { 030 private Callables() {} 031 032 /** 033 * Creates a {@code Callable} which immediately returns a preset value each 034 * time it is called. 035 */ 036 public static <T> Callable<T> returning(final @Nullable T value) { 037 return new Callable<T>() { 038 @Override public T call() { 039 return value; 040 } 041 }; 042 } 043 }