Class Convert
java.lang.Object
cloud.opencode.base.core.convert.Convert
Unified Type Conversion Entry - Static methods for type conversion
统一类型转换入口 - 类型转换的静态方法
Provides convenient static methods for common type conversions using registered converters.
提供使用注册转换器的常用类型转换便捷静态方法。
Features | 主要功能:
- Primitive conversions (toInt, toLong, toDouble, toBoolean) - 基本类型转换
- String conversion (toStr) - 字符串转换
- Date/Time conversion (toDate, toLocalDate, toLocalDateTime) - 日期时间转换
- Array conversion (toArray) - 数组转换
- Generic conversion (convert with TypeReference) - 泛型转换
Usage Examples | 使用示例:
// Basic type conversion - 基本类型转换
Integer num = Convert.toInt("123", 0);
Boolean b = Convert.toBool("true");
// Date conversion - 日期转换
LocalDate date = Convert.toLocalDate("2024-01-15");
Security | 安全性:
- Thread-safe: Yes (uses thread-safe registry) - 线程安全: 是 (使用线程安全注册表)
- Null-safe: Yes (returns default on null) - 空值安全: 是 (null 返回默认值)
- Since:
- JDK 25, opencode-base-core V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Tconvert(Object value, TypeReference<T> typeRef) Generic type conversion (using TypeReference) 泛型转换(使用 TypeReference)static <T> TGeneric type conversion 泛型转换static BooleanConverts the given value to Boolean.static BooleanConverts the given value to Boolean, returning the default value if conversion fails.static ByteConverts the given value to Byte.static ByteConverts the given value to Byte, returning the default value if conversion fails.static CharacterConverts the given value to Character.static CharacterConverts the given value to Character, returning the default value if conversion fails.static DoubleConverts the given value to Double.static DoubleConverts the given value to Double, returning the default value if conversion fails.static FloatConverts the given value to Float.static FloatConverts the given value to Float, returning the default value if conversion fails.static IntegerConverts the given value to Integer.static IntegerConverts the given value to Integer, returning the default value if conversion fails.static int[]toIntArray(Object value) Converts the given value to an int array.static <T> List<T> Converts the given value to a List of the specified element type.static LongConverts the given value to Long.static LongConverts the given value to Long, returning the default value if conversion fails.static long[]toLongArray(Object value) Converts the given value to a long array.static <T> Set<T> Converts the given value to a Set of the specified element type.static ShortConverts the given value to Short.static ShortConverts the given value to Short, returning the default value if conversion fails.static StringConverts the given value to String.static StringConverts the given value to String, returning the default value if conversion fails.static String[]toStrArray(Object value) Converts the given value to a String array.
-
Method Details
-
toInt
-
toInt
-
toLong
-
toLong
-
toDouble
-
toDouble
-
toFloat
-
toFloat
-
toShort
-
toShort
-
toByte
-
toByte
-
toBool
-
toBool
-
toChar
-
toChar
-
toStr
-
toStr
-
toIntArray
Converts the given value to an int array. 转换为 int 数组 -
toLongArray
Converts the given value to a long array. 转换为 long 数组 -
toStrArray
-
toList
-
toSet
-
convert
-
convert
Generic type conversion (using TypeReference) 泛型转换(使用 TypeReference)
-