Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
f4038634
Commit
f4038634
authored
Apr 19, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
类型转换
parent
e668000c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
3 deletions
+17
-3
ObjectHelper.java
...src/main/java/com/yanzuoguang/util/base/ObjectHelper.java
+8
-1
StringHelper.java
...c/main/java/com/yanzuoguang/util/helper/StringHelper.java
+9
-2
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/base/ObjectHelper.java
View file @
f4038634
...
...
@@ -405,7 +405,14 @@ public class ObjectHelper {
* @throws InstantiationException 异常信息
*/
public
static
<
T
>
T
convert
(
Class
<
T
>
toCls
,
Object
from
)
throws
IllegalAccessException
,
InstantiationException
{
T
to
=
toCls
.
newInstance
();
if
(
from
==
null
)
{
return
null
;
}
T
to
=
StringHelper
.
to
(
toCls
,
from
);
if
(
to
!=
null
)
{
return
to
;
}
to
=
toCls
.
newInstance
();
writeWithToClass
(
to
,
from
);
return
to
;
}
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/StringHelper.java
View file @
f4038634
package
com
.
yanzuoguang
.
util
.
helper
;
import
com.yanzuoguang.util.base.ObjectHelper
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
...
...
@@ -118,7 +119,7 @@ public class StringHelper {
if
(
(
chars
[
start
+
1
]
==
'x'
)
||
(
chars
[
start
+
1
]
==
'X'
)
)
{
// leading 0x/0X
)
{
// leading 0x/0X
int
i
=
start
+
2
;
if
(
i
==
sz
)
{
return
false
;
// str == "0x"
...
...
@@ -248,6 +249,9 @@ public class StringHelper {
* @return 返回获取的值
*/
public
static
<
T
>
T
to
(
Class
<
T
>
cls
,
Object
from
)
{
if
(
from
==
null
)
{
return
null
;
}
String
vName
=
cls
.
getName
();
Object
to
=
null
;
if
(
cls
.
isEnum
())
{
...
...
@@ -272,7 +276,10 @@ public class StringHelper {
if
(
to
!=
null
)
{
return
(
T
)
to
;
}
else
{
return
(
T
)
from
;
if
(
ObjectHelper
.
isSub
(
cls
,
from
.
getClass
()))
{
return
(
T
)
from
;
}
return
(
T
)
to
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment