File tree Expand file tree Collapse file tree 2 files changed +9
-26
lines changed
Expand file tree Collapse file tree 2 files changed +9
-26
lines changed Original file line number Diff line number Diff line change @@ -85,34 +85,23 @@ class Box
8585 /**
8686 * @param T $value
8787 */
88- public function __construct($value)
88+ public function __construct(private mixed $value)
8989 {
90- $this->value = $value;
9190 }
9291}
9392```
9493
94+ Small ** ad break** for [ Scala] ( https://www.scala-lang.org/ ) . The same code in Scala 3 looks like this:
95+ ``` scala
96+ case class Box [T ](value : T )
97+ ```
98+ /ad-break
99+
95100The ` @template T ` annotation tells PHPStan that the class is generic and that the type of the value is T.
96101In the constructor, we use the $value parameter with the type T,
97102and the type of the Box is automatically reverse engineered from the input.
98103
99- Small ** ad break** for [ Scala] ( https://www.scala-lang.org/ ) . The ENTIRE above code in Scala 3 looks like this:
100- ``` scala
101- class Box [T ](value : T )
102- ```
103- To add insult to injury, Scala has extension methods that you can add to any class on the fly. So no Box class
104- is needed. You can just write:
105- ``` scala
106- import scala .util .chaining .*
107-
108- " Hello World"
109- .toCharArray
110- .map(_.toInt)
111- .sum
112- .pipe(n => s " The number is $n" )
113- .tap(println) // prints "The number is 1052"
114- ```
115- /ad-break
104+
116105
117106Examples:
118107- ` Box::of(5) ` will be of type ` Box<int> `
Original file line number Diff line number Diff line change 1313 */
1414class Box
1515{
16- /**
17- * @var T
18- */
19- private $ value ;
20-
2116 /**
2217 * @template U
2318 * @param U $value
@@ -31,9 +26,8 @@ public static function of($value): Box
3126 /**
3227 * @param T $value
3328 */
34- public function __construct ($ value )
29+ public function __construct (private mixed $ value )
3530 {
36- $ this ->value = $ value ;
3731 }
3832
3933 /**
You can’t perform that action at this time.
0 commit comments