How to call java method taking parameter as List<Class> from ScalaHow do I use reflection to call a generic method?How do I call one constructor from another in Java?How do I create a Java string from the contents of a file?How do I address unchecked cast warnings?How to get an enum value from a string value in Java?Efficiency of Java “Double Brace Initialization”?Where does Scala look for implicits?How to convert a java.util.List to a Scala listTranslating generic wildcards from Java to ScalaPlay! failing to convert java list to scala list

What is a Centaur Thief's climbing speed?

Have 1.5% of all nuclear reactors ever built melted down?

Using credit/debit card details vs swiping a card in a payment (credit card) terminal

Need to understand my home electrical meter to see why bill is so high and/or if neighbor is on same meter

High resistance, no current. What's the point of a potential then?

Any advice on creating fictional locations in real places when writing historical fiction?

How strong are Wi-Fi signals?

My employer faked my resume to acquire projects

Sitecore 9.0 works with solr 7.2.1?

What to keep in mind when telling an aunt how wrong her actions are, without creating further family conflict?

Python program to take in two strings and print the larger string

Why does Mjolnir fall down in Age of Ultron but not in Endgame?

A Riley Respite

Teacher help me explain this to my students

Can I tell a prospective employee that everyone in the team is leaving?

Count Even Digits In Number

Compaq Portable vs IBM 5155 Portable PC

Website returning plaintext password

Is it rude to call a professor by their last name with no prefix in a non-academic setting?

I unknowingly submitted plagarised work

NIntegrate doesn't evaluate

How to Pin Point Large File eating space in Fedora 18

Python program to find the most frequent letter in a text

How did these characters "suit up" so quickly?



How to call java method taking parameter as List> from Scala


How do I use reflection to call a generic method?How do I call one constructor from another in Java?How do I create a Java string from the contents of a file?How do I address unchecked cast warnings?How to get an enum value from a string value in Java?Efficiency of Java “Double Brace Initialization”?Where does Scala look for implicits?How to convert a java.util.List to a Scala listTranslating generic wildcards from Java to ScalaPlay! failing to convert java list to scala list






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








4















I am trying to call a java method which takes List<Class<?>> from scala.



The compilation fails with



type mismatch;
found : java.util.List[Class[T]] where type T <: Person.type
required: java.util.List[Class[_]]


I tried using JavaConverters but get the same error.



Java method:



void registerClasses(List<Class<?>> var1);



Calling from Scala:



def registerEntities() = registry.registerClasses(List(Person.getClass).asJava)










share|improve this question
























  • Not a solution, but what happens when you change the Java side to use a raw type, so just List var1)?

    – GhostCat
    Mar 24 at 4:59











  • @GhostCat - Java side is a third party library. So, can't really change it.

    – sooper
    Mar 24 at 5:12


















4















I am trying to call a java method which takes List<Class<?>> from scala.



The compilation fails with



type mismatch;
found : java.util.List[Class[T]] where type T <: Person.type
required: java.util.List[Class[_]]


I tried using JavaConverters but get the same error.



Java method:



void registerClasses(List<Class<?>> var1);



Calling from Scala:



def registerEntities() = registry.registerClasses(List(Person.getClass).asJava)










share|improve this question
























  • Not a solution, but what happens when you change the Java side to use a raw type, so just List var1)?

    – GhostCat
    Mar 24 at 4:59











  • @GhostCat - Java side is a third party library. So, can't really change it.

    – sooper
    Mar 24 at 5:12














4












4








4








I am trying to call a java method which takes List<Class<?>> from scala.



The compilation fails with



type mismatch;
found : java.util.List[Class[T]] where type T <: Person.type
required: java.util.List[Class[_]]


I tried using JavaConverters but get the same error.



Java method:



void registerClasses(List<Class<?>> var1);



Calling from Scala:



def registerEntities() = registry.registerClasses(List(Person.getClass).asJava)










share|improve this question
















I am trying to call a java method which takes List<Class<?>> from scala.



The compilation fails with



type mismatch;
found : java.util.List[Class[T]] where type T <: Person.type
required: java.util.List[Class[_]]


I tried using JavaConverters but get the same error.



Java method:



void registerClasses(List<Class<?>> var1);



Calling from Scala:



def registerEntities() = registry.registerClasses(List(Person.getClass).asJava)







java scala generics






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 7:55









pme

4,11511935




4,11511935










asked Mar 24 at 3:50









soopersooper

233




233












  • Not a solution, but what happens when you change the Java side to use a raw type, so just List var1)?

    – GhostCat
    Mar 24 at 4:59











  • @GhostCat - Java side is a third party library. So, can't really change it.

    – sooper
    Mar 24 at 5:12


















  • Not a solution, but what happens when you change the Java side to use a raw type, so just List var1)?

    – GhostCat
    Mar 24 at 4:59











  • @GhostCat - Java side is a third party library. So, can't really change it.

    – sooper
    Mar 24 at 5:12

















Not a solution, but what happens when you change the Java side to use a raw type, so just List var1)?

– GhostCat
Mar 24 at 4:59





Not a solution, but what happens when you change the Java side to use a raw type, so just List var1)?

– GhostCat
Mar 24 at 4:59













@GhostCat - Java side is a third party library. So, can't really change it.

– sooper
Mar 24 at 5:12






@GhostCat - Java side is a third party library. So, can't really change it.

– sooper
Mar 24 at 5:12













1 Answer
1






active

oldest

votes


















3














The problem is that the inferred type for Person.getClass is not the one you want. You need to specify the expected type, and this can be done by an explicit type parameter



registry.registerClasses(List[Class[_]](Person.getClass).asJava)


(I don't understand why type ascription doesn't work here:



registerClasses(List(Person.getClass: Class[_]).asJava)

type mismatch;
found : java.util.List[Class[_$2]] where type _$2
required: java.util.List[Class[_]]
Note: Class[_$2] <: Class[_], but Java-defined trait List is invariant in type E.
You may wish to investigate a wildcard type such as `_ <: Class[_]`. (SLS 3.2.10)


So far as I can tell it should.)






share|improve this answer




















  • 2





    I can't get the type ascription to work, but it seems the type parameter works, so +1.

    – Brian McCutchon
    Mar 24 at 6:43











  • @BrianMcCutchon That's really surprising, thanks.

    – Alexey Romanov
    Mar 24 at 7:16











  • @Alexey Romanov - Thanks. Type parameter works. However, it puzzles me why implicit conversion doesn't. IntelliJ doesn't complain but maven compilation fails.

    – sooper
    Mar 25 at 0:57











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320574%2fhow-to-call-java-method-taking-parameter-as-listclass-from-scala%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














The problem is that the inferred type for Person.getClass is not the one you want. You need to specify the expected type, and this can be done by an explicit type parameter



registry.registerClasses(List[Class[_]](Person.getClass).asJava)


(I don't understand why type ascription doesn't work here:



registerClasses(List(Person.getClass: Class[_]).asJava)

type mismatch;
found : java.util.List[Class[_$2]] where type _$2
required: java.util.List[Class[_]]
Note: Class[_$2] <: Class[_], but Java-defined trait List is invariant in type E.
You may wish to investigate a wildcard type such as `_ <: Class[_]`. (SLS 3.2.10)


So far as I can tell it should.)






share|improve this answer




















  • 2





    I can't get the type ascription to work, but it seems the type parameter works, so +1.

    – Brian McCutchon
    Mar 24 at 6:43











  • @BrianMcCutchon That's really surprising, thanks.

    – Alexey Romanov
    Mar 24 at 7:16











  • @Alexey Romanov - Thanks. Type parameter works. However, it puzzles me why implicit conversion doesn't. IntelliJ doesn't complain but maven compilation fails.

    – sooper
    Mar 25 at 0:57















3














The problem is that the inferred type for Person.getClass is not the one you want. You need to specify the expected type, and this can be done by an explicit type parameter



registry.registerClasses(List[Class[_]](Person.getClass).asJava)


(I don't understand why type ascription doesn't work here:



registerClasses(List(Person.getClass: Class[_]).asJava)

type mismatch;
found : java.util.List[Class[_$2]] where type _$2
required: java.util.List[Class[_]]
Note: Class[_$2] <: Class[_], but Java-defined trait List is invariant in type E.
You may wish to investigate a wildcard type such as `_ <: Class[_]`. (SLS 3.2.10)


So far as I can tell it should.)






share|improve this answer




















  • 2





    I can't get the type ascription to work, but it seems the type parameter works, so +1.

    – Brian McCutchon
    Mar 24 at 6:43











  • @BrianMcCutchon That's really surprising, thanks.

    – Alexey Romanov
    Mar 24 at 7:16











  • @Alexey Romanov - Thanks. Type parameter works. However, it puzzles me why implicit conversion doesn't. IntelliJ doesn't complain but maven compilation fails.

    – sooper
    Mar 25 at 0:57













3












3








3







The problem is that the inferred type for Person.getClass is not the one you want. You need to specify the expected type, and this can be done by an explicit type parameter



registry.registerClasses(List[Class[_]](Person.getClass).asJava)


(I don't understand why type ascription doesn't work here:



registerClasses(List(Person.getClass: Class[_]).asJava)

type mismatch;
found : java.util.List[Class[_$2]] where type _$2
required: java.util.List[Class[_]]
Note: Class[_$2] <: Class[_], but Java-defined trait List is invariant in type E.
You may wish to investigate a wildcard type such as `_ <: Class[_]`. (SLS 3.2.10)


So far as I can tell it should.)






share|improve this answer















The problem is that the inferred type for Person.getClass is not the one you want. You need to specify the expected type, and this can be done by an explicit type parameter



registry.registerClasses(List[Class[_]](Person.getClass).asJava)


(I don't understand why type ascription doesn't work here:



registerClasses(List(Person.getClass: Class[_]).asJava)

type mismatch;
found : java.util.List[Class[_$2]] where type _$2
required: java.util.List[Class[_]]
Note: Class[_$2] <: Class[_], but Java-defined trait List is invariant in type E.
You may wish to investigate a wildcard type such as `_ <: Class[_]`. (SLS 3.2.10)


So far as I can tell it should.)







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 24 at 7:15

























answered Mar 24 at 6:20









Alexey RomanovAlexey Romanov

113k26218363




113k26218363







  • 2





    I can't get the type ascription to work, but it seems the type parameter works, so +1.

    – Brian McCutchon
    Mar 24 at 6:43











  • @BrianMcCutchon That's really surprising, thanks.

    – Alexey Romanov
    Mar 24 at 7:16











  • @Alexey Romanov - Thanks. Type parameter works. However, it puzzles me why implicit conversion doesn't. IntelliJ doesn't complain but maven compilation fails.

    – sooper
    Mar 25 at 0:57












  • 2





    I can't get the type ascription to work, but it seems the type parameter works, so +1.

    – Brian McCutchon
    Mar 24 at 6:43











  • @BrianMcCutchon That's really surprising, thanks.

    – Alexey Romanov
    Mar 24 at 7:16











  • @Alexey Romanov - Thanks. Type parameter works. However, it puzzles me why implicit conversion doesn't. IntelliJ doesn't complain but maven compilation fails.

    – sooper
    Mar 25 at 0:57







2




2





I can't get the type ascription to work, but it seems the type parameter works, so +1.

– Brian McCutchon
Mar 24 at 6:43





I can't get the type ascription to work, but it seems the type parameter works, so +1.

– Brian McCutchon
Mar 24 at 6:43













@BrianMcCutchon That's really surprising, thanks.

– Alexey Romanov
Mar 24 at 7:16





@BrianMcCutchon That's really surprising, thanks.

– Alexey Romanov
Mar 24 at 7:16













@Alexey Romanov - Thanks. Type parameter works. However, it puzzles me why implicit conversion doesn't. IntelliJ doesn't complain but maven compilation fails.

– sooper
Mar 25 at 0:57





@Alexey Romanov - Thanks. Type parameter works. However, it puzzles me why implicit conversion doesn't. IntelliJ doesn't complain but maven compilation fails.

– sooper
Mar 25 at 0:57



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320574%2fhow-to-call-java-method-taking-parameter-as-listclass-from-scala%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript