Skip to content

Commit 9bf6907

Browse files
committed
Fixed many compiler warnings after Scala 3.4 migration
1 parent df1fd61 commit 9bf6907

File tree

46 files changed

+93
-93
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+93
-93
lines changed

scala-core-collections-modules/scala-core-collections-3/src/main/scala/com/baeldung/scala/commoncollections/ScalaCollections.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object ScalaCollections {
1010

1111
val numbersListWithOperator: List[Int] = 1 :: 2 :: 3 :: 4 :: Nil
1212
val emptyListWithNil: List[Int] = Nil
13-
val x :: xs = numbersList
13+
val x :: xs = numbersList: @unchecked
1414

1515
// Scala Set
1616
val emptySet: Set[Int] = Set()

scala-core-modules/scala-core-2/src/main/scala/com/baeldung/scala/forcomprehension/ForComprehension.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ object ForComprehension {
5656
def foreach(f: A => Unit): Unit = f(result)
5757
def map[B](f: A => B): Result[B] = Result(f(result))
5858
def flatMap[B](f: A => Result[B]): Result[B] = f(result)
59-
def withFilter(f: A => Boolean): Result[_] =
59+
def withFilter(f: A => Boolean): Result[?] =
6060
if (f(result)) this else EmptyResult
6161
}
6262

scala-core-modules/scala-core-2/src/main/scala/com/baeldung/scala/underscore/UnderscoreUsages.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.baeldung.scala.underscore
22

33
object UnderscoreUsages {
44

5-
def getLength(x: List[List[_]]): Int = x.length
5+
def getLength(x: List[List[?]]): Int = x.length
66

77
def itemTransaction(price: Double): String = {
88
price match {
@@ -33,7 +33,7 @@ object UnderscoreUsages {
3333
}
3434
}
3535

36-
def list_++(list: List[_]): List[_] = List.concat(list, list)
36+
def list_++(list: List[?]): List[?] = List.concat(list, list)
3737

3838
trait ObjectContainer[T[_]] { // higher kinded type parameter
3939
def checkIfEmpty[A](collection: T[A]): Boolean

scala-core-modules/scala-core-2/src/test/scala/com/baeldung/scala/underscore/UnderscoreUsagesUnitTest.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class UnderscoreUsagesUnitTest extends AnyWordSpec with Matchers {
4848
b shouldBe "b"
4949

5050
text = "a,b,c,d,e"
51-
val Array(a2, _*) = text.split(",")
51+
val Array(a2, _*) = text.split(","): @unchecked
5252
a2 shouldBe "a"
5353

5454
val Array(a3, b3, _, d, e) = text.split(",")
@@ -58,20 +58,20 @@ class UnderscoreUsagesUnitTest extends AnyWordSpec with Matchers {
5858
e shouldBe "e"
5959
}
6060
"work in reassigning a a function to a value" in {
61-
val times = multiplier _
61+
val times = multiplier
6262
multiplier(8, 13) shouldBe times(8, 13)
6363
}
6464
"work in converting a sequence to variable arguments" in {
6565
val sumable = Seq(4, 5, 10, 3)
66-
val sumOfSumable = sum(sumable: _*)
66+
val sumOfSumable = sum(sumable*)
6767
sumOfSumable shouldBe 22
6868
}
6969
"generate a partially applied function" in {
7070
val sumToTen = sum(10, _: Int)
7171
val sumFiveAndTen = sumToTen(5)
7272
sumFiveAndTen shouldBe 15
7373

74-
val foo = bar(1, 2) _
74+
val foo = bar(1, 2)
7575
foo("Some string", "Another string")(3 / 5, 6 / 5) shouldBe 1
7676
}
7777
"work in overriding a method's setter" in {

scala-core-modules/scala-core-3/src/main/scala/com/baeldung/scala/accessmodifiers/Figure.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package com.baeldung.scala.accessmodifiers
33
import java.util.UUID.randomUUID
44

55
abstract class Figure {
6-
private[this] val code =
6+
private val code =
77
randomUUID.toString // accessible in the scope of the object-only
88
def printCode: Unit = println(s"$code") // public access
99

1010
protected[accessmodifiers] val color: String // accessible in the scope of the package
11-
protected[this] val lineWidth: Int // accessible for instances of this class and its subclasses instances
11+
protected val lineWidth: Int // accessible for instances of this class and its subclasses instances
1212

1313
protected val topPoint: Double // accessible in the scope of the class and subclasses
1414
protected val rightMostPoint: Double

scala-core-modules/scala-core-3/src/main/scala/com/baeldung/scala/iteratorsvsstreamsvsviews/NonStrictDataStructures.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object NonStrictDataStructures {
88
val stream = data.toStream
99
// todo: check if this is ok, better to separate into separate module
1010
// val view: AnyRef with SeqView[Int, Seq[Int]] = data.view
11-
val view: AnyRef with SeqView[Int] = data.view
11+
val view: AnyRef & SeqView[Int] = data.view
1212
}
1313

1414
case class Factorial() {

scala-core-modules/scala-core-3/src/main/scala/com/baeldung/scala/typecasts/TypeErasure.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ object TypeErasure {
1313

1414
// Simply function that converts a variable number of values to a List of that type
1515
def convertValuesToList[T](values: T*): List[T] = {
16-
List[T](values: _*)
16+
List[T](values*)
1717
}
1818
}

scala-core-modules/scala-core-3/src/test/scala/com/baeldung/scala/typecasts/TypeErasureUnitTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class TypeErasureUnitTest extends AnyWordSpec with Matchers {
3939
"work with varargs" in {
4040
def varargFn(str: String*) = str.length
4141
val input = Seq("Hello", "World")
42-
assert(varargFn(input: _*) == 2)
42+
assert(varargFn(input*) == 2)
4343
}
4444
}
4545
}

scala-core-modules/scala-core-6/src/main/scala/com/baeldung/scala/functions/Functions.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ object Functions {
3535
// getNameLengthDef.andThen(multiplyByTwoDef) //doesn't compile
3636

3737
/** Method to Function value */
38-
val getNameLengthDefFnValue = getNameLengthDef _
39-
val multiplyByTwoDefFnValue = multiplyByTwoDef _
38+
val getNameLengthDefFnValue = getNameLengthDef
39+
val multiplyByTwoDefFnValue = multiplyByTwoDef
4040

4141
getNameLengthDefFnValue.andThen(multiplyByTwoDefFnValue) // compiles
4242

scala-core-modules/scala-core-7/src/main/scala/com/baeldung/scala/productserializable/ColorInference.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ object ColorV2 {
1414

1515
object Inference {
1616
def isError: Boolean = true
17-
val consoleColor: Product with Serializable with Color =
17+
val consoleColor: Product & Serializable & Color =
1818
if (isError) Color.Red else Color.Green
1919

2020
val consoleColorV2: Color = if (isError) Color.Red else Color.Green

0 commit comments

Comments
 (0)