Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kurs_java_alx_20240321
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
kurs_java_alx_20240321
Commits
f135c443
Commit
f135c443
authored
Apr 12, 2024
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unmodifiableList
parent
804288b8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
2 deletions
+4
-2
Program.java
src/p11_klasy/enkapsulacja/Program.java
+1
-1
Student.java
src/p11_klasy/enkapsulacja/Student.java
+3
-1
No files found.
src/p11_klasy/enkapsulacja/Program.java
View file @
f135c443
...
@@ -26,7 +26,7 @@ public class Program {
...
@@ -26,7 +26,7 @@ public class Program {
// próba modyfikacji listy za pośrednictwem gettera
// próba modyfikacji listy za pośrednictwem gettera
List
<
Integer
>
lista
=
student
.
getOceny
();
List
<
Integer
>
lista
=
student
.
getOceny
();
System
.
out
.
println
(
lista
);
System
.
out
.
println
(
lista
);
lista
.
removeIf
(
x
->
x
<
4
);
// usuń wszystkie oceny gorsze niż 4
lista
.
removeIf
(
x
->
x
<
4
);
// usuń wszystkie oceny gorsze niż 4
- w wersji unmodifiable wyrzuca wyjątek
System
.
out
.
println
(
lista
);
System
.
out
.
println
(
lista
);
System
.
out
.
println
(
"średnia: "
+
student
.
sredniaOcen
());
System
.
out
.
println
(
"średnia: "
+
student
.
sredniaOcen
());
}
}
...
...
src/p11_klasy/enkapsulacja/Student.java
View file @
f135c443
...
@@ -2,6 +2,7 @@ package p11_klasy.enkapsulacja;
...
@@ -2,6 +2,7 @@ package p11_klasy.enkapsulacja;
import
java.time.LocalDate
;
import
java.time.LocalDate
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
public
class
Student
extends
Osoba
{
public
class
Student
extends
Osoba
{
...
@@ -41,7 +42,8 @@ public class Student extends Osoba {
...
@@ -41,7 +42,8 @@ public class Student extends Osoba {
}
}
public
List
<
Integer
>
getOceny
()
{
public
List
<
Integer
>
getOceny
()
{
return
oceny
;
// zwracamy obiekt, poprzez który nie jest możliwa modyfikacja
return
Collections
.
unmodifiableList
(
oceny
);
}
}
public
double
sredniaOcen
()
{
public
double
sredniaOcen
()
{
...
...
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