Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
2
20230403
Overview
Overview
Details
Activity
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
Patryk Czarnik
20230403
Commits
cf48da25
Commit
cf48da25
authored
May 11, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Poprawka w toString() w nadklasie za pomocą refleksji
parent
fb89df30
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
9 deletions
+44
-9
WspolnaNadklasa.java
...-Hibernate/src/main/java/sklep/model/WspolnaNadklasa.java
+28
-0
WspolnaNadklasa.java
...klepSpring/src/main/java/sklep/model/WspolnaNadklasa.java
+16
-9
No files found.
PC27-Hibernate/src/main/java/sklep/model/WspolnaNadklasa.java
View file @
cf48da25
package
sklep
.
model
;
import
java.lang.reflect.Field
;
abstract
class
WspolnaNadklasa
{
@Override
public
String
toString
()
{
StringBuilder
result
=
new
StringBuilder
();
Class
<?
extends
WspolnaNadklasa
>
klasa
=
this
.
getClass
();
result
.
append
(
klasa
.
getSimpleName
()).
append
(
" ["
);
int
fieldNo
=
0
;
for
(
Field
field
:
klasa
.
getDeclaredFields
())
try
{
if
(
fieldNo
++
>
0
)
{
result
.
append
(
", "
);
}
Object
value
;
if
(
field
.
trySetAccessible
())
{
value
=
field
.
get
(
this
);
}
else
{
value
=
"!"
;
}
result
.
append
(
field
.
getName
()).
append
(
'='
).
append
(
value
);
}
catch
(
IllegalArgumentException
|
IllegalAccessException
e
)
{
System
.
err
.
println
(
e
);
}
result
.
append
(
"]"
);
return
result
.
toString
();
}
}
PC30-SklepSpring/src/main/java/sklep/model/WspolnaNadklasa.java
View file @
cf48da25
...
...
@@ -8,18 +8,25 @@ abstract class WspolnaNadklasa {
StringBuilder
result
=
new
StringBuilder
();
Class
<?
extends
WspolnaNadklasa
>
klasa
=
this
.
getClass
();
result
.
append
(
klasa
.
getSimpleName
()).
append
(
" ["
);
for
(
Field
field
:
klasa
.
getDeclaredFields
())
{
try
{
// FIXME
//Object value = field.get(this);
result
.
append
(
field
.
getName
()).
append
(
'='
).
append
(
", "
);
}
catch
(
IllegalArgumentException
e
)
{
System
.
err
.
println
(
e
);
int
fieldNo
=
0
;
for
(
Field
field
:
klasa
.
getDeclaredFields
())
try
{
if
(
fieldNo
++
>
0
)
{
result
.
append
(
", "
);
}
Object
value
;
if
(
field
.
trySetAccessible
())
{
value
=
field
.
get
(
this
);
}
else
{
value
=
"!"
;
}
result
.
append
(
field
.
getName
()).
append
(
'='
).
append
(
value
);
}
catch
(
IllegalArgumentException
|
IllegalAccessException
e
)
{
System
.
err
.
println
(
e
);
}
result
.
append
(
"]"
);
return
result
.
toString
();
}
...
...
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