335 questions
3
votes
0
answers
102
views
How to override a varargs java method in a scala class which is still callable in both scala and java variadically?
Assume there is a base class in a Java library which cannot be modified
public class BaseClass {
public Something function(int... args){ ... }
}
Typically, this would be overridden in Scala by ...
0
votes
3
answers
147
views
How to convert Scala `for..yield` (for comprehension) to Java?
How to convert the following scala to java code?
for {
x <- List(1, 2)
y <- List(3, 4)
} yield (x, y)
Is it possible? what is yield?
I guess it's possible to convert any scala code to java.....
1
vote
1
answer
99
views
Subclassing and overriding Java class with protected field access
The scala project is depending on the Java lib that I cannot modify. I need to extend one of the Java classes and override method, however I have issues with protected visibility:
package com.a;
...
2
votes
1
answer
73
views
Scala class implementing Java interface - double definition with same erasure
I hava a Java interface:
public interface FooJava {
void consume(String... strings);
void consume(Integer... ints);
}
and I want to implement it in Scala:
class BarScala extends FooJava {
...
0
votes
1
answer
64
views
Scala class implementing Java interface - how to implement method taking array of generic type
I hava a Java interface:
public interface FooJava<Element> {
void consume(Element[] elements);
// more methods
}
and I want to implement it in Scala:
// attempt 1
class BarScala[T] extends ...
0
votes
1
answer
135
views
invoking scala generic classes from java looses generic info
trying to use in java class defined in scala library.
Definition:
final class ScenarioBuilder(...) extends StructureBuilder[ScenarioBuilder]
trait StructureBuilder[B <: StructureBuilder[B]] extends ...
0
votes
0
answers
26
views
how to convert java stream to scala stream? [duplicate]
want to iterate thru bidChoices list and map using scala, below is the java code. what to perform the same using scala.
private String generateRestBody(String baseUrl, String auctionId, String ...
0
votes
1
answer
177
views
Scala: type hint for lambda
I'm refreshing scala. This looks very simple to me but I can't get it to run:
import java.nio.file.{FileSystems, Files}
object ScalaHello extends App {
val dir = FileSystems.getDefault.getPath(&...
0
votes
0
answers
143
views
How to declare optional basic type in scala e.g. Option[Int] so that the type gets seen as Option<Integer> from java?
Consider the following scala class:
class Demo {
def mandatoryInt: Int = 42
def optInt: Option[Int] = Some(1)
def optString: Option[String] = Some("demo")
}
When its methods are ...
0
votes
1
answer
741
views
Import Scala object within object in Java
I have an object within another object in Scala which I want to import in Java. The setup is something like this:
Scala:
package scalapart;
object Outer {
object Inner {
def method: ...
3
votes
2
answers
157
views
Instanciating POJO with nulls values from Scala Option
Many years of using Scala and still I don't know the right way to interoperate with Java. :(
To be honest, this is not something that I'm doing every day, but sometimes there is no other option (today ...
1
vote
1
answer
230
views
Implementing Java interface in Scala results in incompatible type map
I have a Java interface that I want to implement in Scala. The interface contains the following method-declaration:
List<Map<String, Object>> xyz(Map<String, Object> var1, Map<...
0
votes
2
answers
146
views
couldn't extend scala class from java class which has abstract function which takes inner class as parameter
I've scala - java polyglot project with scala version 2.13
Below is the standard project structure
$scala-java-extend-demo on master
± tree .
.
├── build.gradle.kts
├── gradlew
...
2
votes
0
answers
173
views
java/scala incompatible types, when casing (or using instanceof) a scala class to java class, even though the scala class extends the java class
this is pretty much the code setup:
// java
public class JavaA {
}
// scala
class ScalaA() extends JavaA {
}
but then in java, if i have an instance of ScalaA somewhere (or even if its null), but ...
2
votes
1
answer
306
views
How to call Scala curry functions from Java with Generics
A Scala code has a retry mechanism which is based on currying function:
object RetryUtil {
def retry[T](retry: Int, timeout: FiniteDuration)(exc: => T): T = {
//
}
}
I want to call this code ...