Changeset 12987 in josm for trunk/src/org/openstreetmap/josm/tools/Utils.java
- Timestamp:
- 2017-10-12T16:02:15+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Utils.java
r12854 r12987 45 45 import java.util.List; 46 46 import java.util.Locale; 47 import java.util.Optional; 47 48 import java.util.concurrent.ExecutionException; 48 49 import java.util.concurrent.Executor; … … 1731 1732 } 1732 1733 } 1734 1735 /** 1736 * Helper method to replace the "<code>instanceof</code>-check and cast" pattern. 1737 * 1738 * @param <T> the type for the instanceof check and cast 1739 * @param o the object to check and cast 1740 * @param klass the class T 1741 * @return {@link Optional} containing the result of the cast, if it is possible, an empty 1742 * Optional otherwise 1743 */ 1744 @SuppressWarnings("unchecked") 1745 public static <T> Optional<T> instanceOfAndCast(Object o, Class<T> klass) { 1746 if (klass.isInstance(o)) 1747 return Optional.of((T) o); 1748 return Optional.empty(); 1749 } 1750 1733 1751 }
Note:
See TracChangeset
for help on using the changeset viewer.