File tree Expand file tree Collapse file tree 3 files changed +11
-9
lines changed
0-0-intro/src/main/java/com/bobocode/intro
1-0-java-basics/1-3-0-hello-generics/src/main/java/com/bobocode/basics Expand file tree Collapse file tree 3 files changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,8 @@ public class ExerciseIntroduction {
2424 */
2525 public String getWelcomeMessage () {
2626 // todo: implement a method and return a message according to javadoc
27- throw new ExerciseNotCompletedException ();
27+ return "The key to efficient learning is practice!" ;
28+
2829 }
2930
3031 /**
Original file line number Diff line number Diff line change 77 * <p>
88 * todo: refactor this class so it uses generic type "T" and run {@link com.bobocode.basics.BoxTest} to verify it
99 */
10- public class Box {
11- private Object value ;
10+ public class Box < T > {
11+ private T value ;
1212
13- public Box (Object value ) {
13+ public Box (T value ) {
1414 this .value = value ;
1515 }
1616
17- public Object getValue () {
17+ public T getValue () {
1818 return value ;
1919 }
2020
21- public void setValue (Object value ) {
21+ public void setValue (T value ) {
2222 this .value = value ;
2323 }
2424}
Original file line number Diff line number Diff line change 99 */
1010public class BoxDemoApp {
1111 public static void main (String [] args ) {
12- Box intBox = new Box (123 );
13- Box intBox2 = new Box (321 );
14- System .out .println (( int ) intBox .getValue () + ( int ) intBox2 .getValue ());
12+ Box < Integer > intBox = new Box <> (123 );
13+ Box < Integer > intBox2 = new Box <> (321 );
14+ System .out .println (intBox .getValue () + intBox2 .getValue ());
1515
1616 intBox .setValue (222 );
1717 intBox .setValue ("abc" ); // this should not be allowed
1818 // the following code will compile, but will throw runtime exception
1919 System .out .println ((int ) intBox .getValue () + (int ) intBox2 .getValue ());
20+
2021 }
2122}
You can’t perform that action at this time.
0 commit comments