Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

类型转换 #323

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/main/java/com/github/hcsp/datatype/Cast.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,48 @@ public class Cast {
// Cast an int to byte
// 将int类型转换成byte
public static byte int2byte(int i) {
return i;
return (byte)i;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

类型转换后应有空格。

}

// Cast an int to short
// 将int类型转换成short
public static short int2short(int i) {
return i;
return (short)i;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

类型转换后应有空格。

}

// Cast an int to char
// 将int类型转换成char
public static char int2char(int i) {
return i;
return (char)i;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

类型转换后应有空格。

}

// Cast an int to String, e.g. 123 -> "123"
// 将一个整数转换为字符串,例如,将123转换成字符串"123"
public static String int2String(int i) {
return i;
return String.valueOf(i) ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

';' 前不应有空格。

}

// Cast an String to int, e.g. "123" -> 123
// 将一个字符串转换成整数,例如,将字符串"123"转换成整数123
public static int string2int(String s) {
return s;
return Integer.parseInt(s);
}

// Cast an String to double, e.g. "1.23" -> 1.23
// 将一个字符串转换成double类型,例如,将字符串"1.23"转换成1.23
public static double string2double(String s) {
return s;
return Double.parseDouble(s);
}

// Cast an Long to int
// 将Long类型转换成int
public static int Long2int(Long l) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

名称 'Long2int' 必须匹配表达式: '^[a-z一-鿿][a-zA-Z0-9一-鿿]*$' 。

return l;
return Math.toIntExact(l);
}

// Cast an Double to long
// 将Double类型转换成long
public static long double2Long(Double d) {
return d;
return Long.parseLong(String.valueOf(d));
}
}