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

scala-core-modules/scala-core-7/src/test/scala/com/baeldung/scala/arrays/CopyAnArrayToAnotherUnitTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class CopyAnArrayToAnotherUnitTest extends AnyFlatSpec with Matchers {
77
val array1 = Array(1, 2, 3, 4)
88

99
"splat operator" should "copy an entire array to another" in {
10-
var array2 = Array(array1: _*)
10+
var array2 = Array(array1*)
1111
array1(1) should be(array2(1))
1212
array1 should not be (array2)
1313

scala-core-modules/scala-core-7/src/test/scala/com/baeldung/scala/arrays/InitializeAnArrayUnitTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class InitializeAnArrayUnitTest extends AnyFlatSpec with Matchers {
3030

3131
"splat operator" should "copy an entire list to an array" in {
3232
var list = List(1, 2, 3, 4)
33-
var array = Array[Int](list: _*)
33+
var array = Array[Int](list*)
3434

3535
array(1) should be(list(1))
3636
array.length should be(4)

scala-core-modules/scala-core-8/src/main/scala/com/baeldung/scala/braces/NoParenthesis.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ object NoParenthesis extends App {
99
// greet "Alice"
1010

1111
// But this works and it equivalent to greet("Alice")
12-
this greet "Alice"
12+
this `greet` "Alice"
1313

1414
}

scala-core-modules/scala-core-8/src/test/scala/com/baeldung/scala/reverselists/ListReverserUnitTest.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ class ListReverserUnitTest extends AnyWordSpec with BeforeAndAfterEach {
99

1010
import ListReverser._
1111

12-
def testReverseSmallList(f: Seq[_] => Seq[_]): Assertion = {
12+
def testReverseSmallList(f: Seq[?] => Seq[?]): Assertion = {
1313
val list = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
1414
val expectedReversedList = List(10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
1515
val actualReversedList = f(list)
1616
assertResult(expectedReversedList)(actualReversedList)
1717
}
1818

19-
def testReverseBigList(f: Seq[_] => Seq[_]): Assertion = {
19+
def testReverseBigList(f: Seq[?] => Seq[?]): Assertion = {
2020
val n = 100_000
2121
val vector: Vector[String] =
2222
(0 to n).foldLeft(Vector.empty[String])((v, _) =>
@@ -29,7 +29,7 @@ class ListReverserUnitTest extends AnyWordSpec with BeforeAndAfterEach {
2929
}
3030

3131
"The naive list reverser" should {
32-
val reversingFunction: Seq[_] => Seq[_] = naiveRecursiveReverse
32+
val reversingFunction: Seq[?] => Seq[?] = naiveRecursiveReverse
3333

3434
"reverse small lists" in {
3535
testReverseSmallList(reversingFunction)
@@ -41,7 +41,7 @@ class ListReverserUnitTest extends AnyWordSpec with BeforeAndAfterEach {
4141
}
4242

4343
"The tail-recursive list reverser" should {
44-
val reversingFunction: Seq[_] => Seq[_] = tailRecursiveReverse
44+
val reversingFunction: Seq[?] => Seq[?] = tailRecursiveReverse
4545

4646
"reverse small lists" in {
4747
testReverseSmallList(reversingFunction)
@@ -53,7 +53,7 @@ class ListReverserUnitTest extends AnyWordSpec with BeforeAndAfterEach {
5353
}
5454

5555
"The folding list reverser" should {
56-
val reversingFunction: Seq[_] => Seq[_] = foldBasedReverse
56+
val reversingFunction: Seq[?] => Seq[?] = foldBasedReverse
5757

5858
"reverse small lists" in {
5959
testReverseSmallList(reversingFunction)

scala-core-modules/scala-core-9/src/test/scala/com/baeldung/scala/classT/ClassTUnitTest.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ClassTUnitTest extends AnyFlatSpec with Matchers {
1919
)
2020

2121
// Instantiate the class with arguments
22-
Some(constructor.newInstance(args: _*).asInstanceOf[T])
22+
Some(constructor.newInstance(args*).asInstanceOf[T])
2323
} catch {
2424
case e: Exception =>
2525
println(s"Error creating instance of ${clazz.getName}: ${e.getMessage}")
@@ -37,7 +37,7 @@ class ClassTUnitTest extends AnyFlatSpec with Matchers {
3737

3838
"createInstance with .getClass" should "successfully create another instance of Person" in {
3939
val dummyPerson = new Person("Dummy")
40-
val personClass: Class[_ <: Person] = dummyPerson.getClass
40+
val personClass: Class[? <: Person] = dummyPerson.getClass
4141
val personInstance = createInstance(personClass, Array("Jane Doe": AnyRef))
4242

4343
personInstance should not be empty
@@ -46,7 +46,7 @@ class ClassTUnitTest extends AnyFlatSpec with Matchers {
4646

4747
"createInstance with .getClass" should "use the type of the variable to bound the type" in {
4848
val dummyPerson: Object = new Person("Dummy")
49-
val personClass: Class[_ <: AnyRef] = dummyPerson.getClass
49+
val personClass: Class[? <: AnyRef] = dummyPerson.getClass
5050
val personInstance = createInstance(personClass, Array("Jane Doe": AnyRef))
5151

5252
personInstance should not be empty

scala-core-modules/scala-core-9/src/test/scala/com/baeldung/scala/destructuring/DestructuringUnitTest.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ class DestructuringUnitTest extends AnyFlatSpec with Matchers {
2828
// Reassemble and call the specific handler
2929
processEmail(
3030
Email(subject, body, recipient)
31-
).msg startsWith ("Sent email to ")
31+
).msg `startsWith` ("Sent email to ")
3232

3333
case SMS(number, message) =>
3434
println(s"Logging SMS to $number: $message")
3535
// Reassemble and call the specific handler
36-
processSMS(SMS(number, message)).msg startsWith ("Sending SMS to")
36+
processSMS(SMS(number, message)).msg `startsWith` ("Sending SMS to")
3737
}
3838
}
3939

@@ -46,46 +46,46 @@ class DestructuringUnitTest extends AnyFlatSpec with Matchers {
4646
// Reassemble and call the specific handler
4747
processEmail(
4848
email
49-
).msg startsWith ("Sent email to ")
49+
).msg `startsWith` ("Sent email to ")
5050

5151
case sms: SMS =>
5252
println(s"Logging SMS to ${sms.number}: ${sms.message}")
5353
// Reassemble and call the specific handler
54-
processSMS(sms).msg startsWith ("Sending SMS to")
54+
processSMS(sms).msg `startsWith` ("Sending SMS to")
5555
}
5656
}
5757

5858
"We" should "be able to pattern match with @" in {
5959
getRandomElement(notifications, random) match {
6060
case email @ Email(subject, _, recipient) =>
6161
println(s"Logging Email to $recipient with subject $subject")
62-
processEmail(email).msg startsWith ("Sent email to ")
62+
processEmail(email).msg `startsWith` ("Sent email to ")
6363

6464
case sms @ SMS(number, message) =>
6565
println(s"Logging SMS to $number: $message")
6666
// Reassemble and call the specific handler
67-
processSMS(sms).msg startsWith ("Sending SMS to")
67+
processSMS(sms).msg `startsWith` ("Sending SMS to")
6868
}
6969
}
7070

7171
"We" should "be able to use @ while declaring a variable" in {
7272
val email @ Email(subject, _, recipient) = getRandomElement(emails, random)
7373
println(s"Logging Email to $recipient with subject $subject")
74-
processEmail(email).msg startsWith ("Sent email to ")
74+
processEmail(email).msg `startsWith` ("Sent email to ")
7575
}
7676

7777
"We" should "be able to use @ in for comprehensions" in {
7878
for (email @ Email(subject, _, recipient) <- emails) {
7979
println(s"Logging Email to $recipient with subject $subject")
80-
processEmail(email).msg startsWith ("Sent email to ")
80+
processEmail(email).msg `startsWith` ("Sent email to ")
8181
}
8282
}
8383

8484
"We" should "be able to use @ in a subpattern" in {
8585
emails match {
8686
case _ :: (email2 @ Email(subject, _, recipient)) :: _ =>
8787
println(s"Logging 2nd Email to $recipient with subject $subject")
88-
processEmail(email2).msg startsWith ("Sent email to ")
88+
processEmail(email2).msg `startsWith` ("Sent email to ")
8989

9090
case _ =>
9191
println(s"Only one message")

scala-core-modules/scala-core-fp/src/test/scala/com/baeldung/scala/currying/CurryingUnitTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class CurryingUnitTest extends Matchers {
2020
: Unit = {
2121
def sum(x: Int, y: Int): Int = x + y
2222

23-
val curriedSum: Int => Int => Int = (sum _).curried
23+
val curriedSum: Int => Int => Int = (sum).curried
2424

2525
sum(1, 2) shouldBe 3
2626
curriedSum(1)(2) shouldBe 3

scala-core-modules/scala-core-oop/src/main/scala/com/baeldung/scala/generics/GenericsIntro.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ object GenericsIntro {
6969
}
7070

7171
object NonGenericMethods {
72-
def totalSize(list1: List[_], list2: List[_]): Int =
72+
def totalSize(list1: List[?], list2: List[?]): Int =
7373
list1.length + list2.length
7474
def run() = {
7575
val rabbits = List[Rabbit](Rabbit(2), Rabbit(3), Rabbit(7))

scala-core-modules/scala-core-oop/src/main/scala/com/baeldung/scala/lifting/Examples.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ object Examples {
3131
def add5(x: Int) = x + 5
3232
def isEven(x: Int) = x % 2 == 0
3333

34-
val funcAdd5 = add5 _
35-
val funcIsEven = isEven _
34+
val funcAdd5 = add5
35+
val funcIsEven = isEven
3636

3737
val sayHello: Future[Option[String]] = Future.successful(Some("Say hello to"))
3838
val firstname: Future[String] = Future.successful("Fabio")

scala-core-modules/scala-core/src/test/scala/com/baeldung/scala/higherorder/HigherOrderFunctionsUnitTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class HigherOrderFunctionsUnitTest {
4040

4141
// partial application of curried function
4242
// trailing underscore is required to make function type explicit
43-
val sumMod5 = sum(mod(5)) _
43+
val sumMod5 = sum(mod(5))
4444

4545
assertEquals(10, sumMod5(6, 10))
4646
}

scala-design-patterns/src/main/scala/com/baeldung/scala/cakepattern/CakePattern.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ object CakePattern {
3636
}
3737

3838
trait TestExecutorComponentWithLogging {
39-
this: TestEnvironmentComponent with LoggingComponent =>
39+
this: TestEnvironmentComponent & LoggingComponent =>
4040
val testExecutor: TestExecutor
4141
class TestExecutor {
4242
def execute(tests: List[Test]): Boolean = {

scala-lang-modules/scala-lang-2/src/test/scala/com/baeldung/scala/voidtypes/NullTypeAndNullValueUnitTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class NullTypeAndNullValueUnitTest extends AnyFunSuite {
1313

1414
test("null equality check using equals ") {
1515
val exceptionThrown = intercept[NullPointerException] {
16-
NullTypeAndnullValue.nullValue equals NullTypeAndnullValue.nullRefCar
16+
NullTypeAndnullValue.nullValue `equals` NullTypeAndnullValue.nullRefCar
1717
}
1818
}
1919

scala-lang-modules/scala-lang-2/src/test/scala/com/baeldung/scala/withtrait/WithTraitUnitTest.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,28 @@ object WithTraitSpec {
5151
val pat: Person =
5252
new Person("Pat", "123 Main St.", LocalDate.of(1933, 10, 11))
5353

54-
val mary: Person with Musician =
54+
val mary: Person & Musician =
5555
new Person("Mary", "456 Second St.", LocalDate.of(1982, 9, 9))
5656
with Musician {
5757
override val instrument: String = "guitar"
5858
}
5959

60-
val prudence: Person with Politician =
60+
val prudence: Person & Politician =
6161
new Person("Prudence", "789 Third St.", LocalDate.of(1972, 6, 3))
6262
with Politician
6363

64-
val giorgio: Person with Politician with Musician =
64+
val giorgio: Person & Politician & Musician =
6565
new Person("Giorgio", "121 Fourth St.", LocalDate.of(1980, 2, 19))
6666
with Politician
6767
with Musician {
6868
override val instrument: String = "flute"
6969
}
7070

71-
val ellie: Animal with Musician =
71+
val ellie: Animal & Musician =
7272
new Animal("Ellie", "elephant") with Musician {
7373
override val instrument: String = "trombone"
7474
}
7575

76-
val vasily: Animal with Politician =
76+
val vasily: Animal & Politician =
7777
new Animal("Vasily", "monkey") with Politician
7878
}

scala-lang-modules/scala-lang/src/main/scala/com/baeldung/scala/operators/ScalaOperators.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ object ScalaOperators {
99
assert(1.+(2) == 3)
1010

1111
assert("Baeldung".charAt(0) == 'B')
12-
val char: Char = "Baeldung" charAt 0
12+
val char: Char = "Baeldung" `charAt` 0
1313
assert(char == 'B')
1414

1515
assert("Baeldung".replace('g', 'G') == "BaeldunG")
16-
val str: String = "Baeldung" replace ('g', 'G')
16+
val str: String = "Baeldung" `replace` ('g', 'G')
1717
assert(str == "BaeldunG")
1818

1919
// Unary operator notation

0 commit comments

Comments
 (0)