Scala conversion to Java function never terminatesImplicit conversion from Scala function to Java FunctionScala vs. Groovy vs. ClojureIs the Scala 2.8 collections library a case of “the longest suicide note in history”?Difference between object and class in ScalaScala puts precedence on implicit conversion over “natural” operations… Why? Is this a bug? Or am I doing something wrong?What are all the uses of an underscore in Scala?Extracting implicit conversion exceptions in partially applied functionsImplicit conversions in scala within a class, why and why not?What method conversion has been applied to this example?Implicit conversions for defs/lambdas in Scala?Implicit Functions in Scala. How is this working?
Meaning of 'ran' in German?
Should we use wheatstone bridges nowadays?
Does Sitecore have support for Sitecore products in containers?
Is the mass of paint relevant in rocket design?
Is it more effective to add yeast before or after kneading?
If an object moving in a circle experiences centripetal force, then doesn't it also experience centrifugal force, because of Newton's third law?
Received a package but didn't order it
extracting sublists
1, 2, 4, 8, 16, ... 33?
Is it a good idea to leave minor world details to the reader's imagination?
How do you use the interjection for snorting?
Hilbert's hotel: why can't I repeat it infinitely many times?
Cut a cake into 3 equal portions with only a knife
Co-supervisor comes to the office to help her students, which distracts me
Is it allowed to buy a Probe Bahncard 50 repeatedly?
Is it acceptable to say that a reviewer's concern is not going to be addressed because then the paper would be too long?
Why did the Soviet Union not "grant" Inner Mongolia to Mongolia after World War Two?
How to create fractional SI units (SI...sqrts)?
Does "as soon as" imply simultaneity?
Line segments inside a square
My manager quit. Should I agree to defer wage increase to accommodate budget concerns?
Does HSTS protect against a rogue CA issuing a illegitimate valid certificate?
How 象【しょう】 ( ≈かたち、 すがた、ようす) and 象【ぞう】 (どうぶつ) got to be written with the same kanji?
On the meaning of 'anyways' in "What Exactly Is a Quartz Crystal, Anyways?"
Scala conversion to Java function never terminates
Implicit conversion from Scala function to Java FunctionScala vs. Groovy vs. ClojureIs the Scala 2.8 collections library a case of “the longest suicide note in history”?Difference between object and class in ScalaScala puts precedence on implicit conversion over “natural” operations… Why? Is this a bug? Or am I doing something wrong?What are all the uses of an underscore in Scala?Extracting implicit conversion exceptions in partially applied functionsImplicit conversions in scala within a class, why and why not?What method conversion has been applied to this example?Implicit conversions for defs/lambdas in Scala?Implicit Functions in Scala. How is this working?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I wrote an implicit conversion from Scala functions to Java functions:
import java.util.function.Function => JavaFunction
implicit def toJavaFunction[T, V](f: (T) => V): JavaFunction[T, V] =
new JavaFunction[T, V]
override def apply(input: T) = f(input)
However, IntelliJ suggests converting this to a single abstract method:
implicit def toJavaFunction[T, V](f: (T) => V): JavaFunction[T, V] =
(input: T) => f(input)
When I change to the second implementation, functions wrapped in this method run forever and execution never terminates. What's different about the second method that's causing it to behave this way? Is there something that IntelliJ is missing?
scala
|
show 2 more comments
I wrote an implicit conversion from Scala functions to Java functions:
import java.util.function.Function => JavaFunction
implicit def toJavaFunction[T, V](f: (T) => V): JavaFunction[T, V] =
new JavaFunction[T, V]
override def apply(input: T) = f(input)
However, IntelliJ suggests converting this to a single abstract method:
implicit def toJavaFunction[T, V](f: (T) => V): JavaFunction[T, V] =
(input: T) => f(input)
When I change to the second implementation, functions wrapped in this method run forever and execution never terminates. What's different about the second method that's causing it to behave this way? Is there something that IntelliJ is missing?
scala
Which version of Scala are you using? Probably the problem is that on your second example basically it seems you are calling yourself recursively... Just that, that's not true, at least since2.12
(I believe this was introduced since2.11
, but not sure tough) that conversion already exists (I can just write this on the REL ` val jf: java.util.function.Function[String, Int] = s => s.toInt`), which probably is why Intellij suggest the change. I tested your second example on the RELP and it works too, so I am not sure what would be the problem on your case.
– Luis Miguel Mejía Suárez
Mar 28 at 18:07
1
@LuisMiguelMejíaSuárez That thes => s.toInt
is accepted asjava.util.function.Function
is not an implicit conversion, it's the SAM. I also couldn't reproduce the problem.
– Andrey Tyukin
Mar 28 at 18:37
@AndreyTyukin Thanks for the clarification, I already knew that it was not an implicit conversion, but something more low level on the compiler. However, did not know what it was. So, thanks for the info both for me and for those reading this.
– Luis Miguel Mejía Suárez
Mar 28 at 18:53
This is on version 2.11. I added the-Xexperimental
flag to my compiler options and now the second option is working as well. I wonder if I have a config mismatch or something in IntelliJ that's telling it that SAM is available by default.
– pbeardshear
Mar 28 at 18:57
Please check stackoverflow.com/questions/36828074/…. Looks like duplicate question.
– KZapagol
Mar 29 at 9:18
|
show 2 more comments
I wrote an implicit conversion from Scala functions to Java functions:
import java.util.function.Function => JavaFunction
implicit def toJavaFunction[T, V](f: (T) => V): JavaFunction[T, V] =
new JavaFunction[T, V]
override def apply(input: T) = f(input)
However, IntelliJ suggests converting this to a single abstract method:
implicit def toJavaFunction[T, V](f: (T) => V): JavaFunction[T, V] =
(input: T) => f(input)
When I change to the second implementation, functions wrapped in this method run forever and execution never terminates. What's different about the second method that's causing it to behave this way? Is there something that IntelliJ is missing?
scala
I wrote an implicit conversion from Scala functions to Java functions:
import java.util.function.Function => JavaFunction
implicit def toJavaFunction[T, V](f: (T) => V): JavaFunction[T, V] =
new JavaFunction[T, V]
override def apply(input: T) = f(input)
However, IntelliJ suggests converting this to a single abstract method:
implicit def toJavaFunction[T, V](f: (T) => V): JavaFunction[T, V] =
(input: T) => f(input)
When I change to the second implementation, functions wrapped in this method run forever and execution never terminates. What's different about the second method that's causing it to behave this way? Is there something that IntelliJ is missing?
scala
scala
asked Mar 28 at 17:41
pbeardshearpbeardshear
4913 silver badges8 bronze badges
4913 silver badges8 bronze badges
Which version of Scala are you using? Probably the problem is that on your second example basically it seems you are calling yourself recursively... Just that, that's not true, at least since2.12
(I believe this was introduced since2.11
, but not sure tough) that conversion already exists (I can just write this on the REL ` val jf: java.util.function.Function[String, Int] = s => s.toInt`), which probably is why Intellij suggest the change. I tested your second example on the RELP and it works too, so I am not sure what would be the problem on your case.
– Luis Miguel Mejía Suárez
Mar 28 at 18:07
1
@LuisMiguelMejíaSuárez That thes => s.toInt
is accepted asjava.util.function.Function
is not an implicit conversion, it's the SAM. I also couldn't reproduce the problem.
– Andrey Tyukin
Mar 28 at 18:37
@AndreyTyukin Thanks for the clarification, I already knew that it was not an implicit conversion, but something more low level on the compiler. However, did not know what it was. So, thanks for the info both for me and for those reading this.
– Luis Miguel Mejía Suárez
Mar 28 at 18:53
This is on version 2.11. I added the-Xexperimental
flag to my compiler options and now the second option is working as well. I wonder if I have a config mismatch or something in IntelliJ that's telling it that SAM is available by default.
– pbeardshear
Mar 28 at 18:57
Please check stackoverflow.com/questions/36828074/…. Looks like duplicate question.
– KZapagol
Mar 29 at 9:18
|
show 2 more comments
Which version of Scala are you using? Probably the problem is that on your second example basically it seems you are calling yourself recursively... Just that, that's not true, at least since2.12
(I believe this was introduced since2.11
, but not sure tough) that conversion already exists (I can just write this on the REL ` val jf: java.util.function.Function[String, Int] = s => s.toInt`), which probably is why Intellij suggest the change. I tested your second example on the RELP and it works too, so I am not sure what would be the problem on your case.
– Luis Miguel Mejía Suárez
Mar 28 at 18:07
1
@LuisMiguelMejíaSuárez That thes => s.toInt
is accepted asjava.util.function.Function
is not an implicit conversion, it's the SAM. I also couldn't reproduce the problem.
– Andrey Tyukin
Mar 28 at 18:37
@AndreyTyukin Thanks for the clarification, I already knew that it was not an implicit conversion, but something more low level on the compiler. However, did not know what it was. So, thanks for the info both for me and for those reading this.
– Luis Miguel Mejía Suárez
Mar 28 at 18:53
This is on version 2.11. I added the-Xexperimental
flag to my compiler options and now the second option is working as well. I wonder if I have a config mismatch or something in IntelliJ that's telling it that SAM is available by default.
– pbeardshear
Mar 28 at 18:57
Please check stackoverflow.com/questions/36828074/…. Looks like duplicate question.
– KZapagol
Mar 29 at 9:18
Which version of Scala are you using? Probably the problem is that on your second example basically it seems you are calling yourself recursively... Just that, that's not true, at least since
2.12
(I believe this was introduced since 2.11
, but not sure tough) that conversion already exists (I can just write this on the REL ` val jf: java.util.function.Function[String, Int] = s => s.toInt`), which probably is why Intellij suggest the change. I tested your second example on the RELP and it works too, so I am not sure what would be the problem on your case.– Luis Miguel Mejía Suárez
Mar 28 at 18:07
Which version of Scala are you using? Probably the problem is that on your second example basically it seems you are calling yourself recursively... Just that, that's not true, at least since
2.12
(I believe this was introduced since 2.11
, but not sure tough) that conversion already exists (I can just write this on the REL ` val jf: java.util.function.Function[String, Int] = s => s.toInt`), which probably is why Intellij suggest the change. I tested your second example on the RELP and it works too, so I am not sure what would be the problem on your case.– Luis Miguel Mejía Suárez
Mar 28 at 18:07
1
1
@LuisMiguelMejíaSuárez That the
s => s.toInt
is accepted as java.util.function.Function
is not an implicit conversion, it's the SAM. I also couldn't reproduce the problem.– Andrey Tyukin
Mar 28 at 18:37
@LuisMiguelMejíaSuárez That the
s => s.toInt
is accepted as java.util.function.Function
is not an implicit conversion, it's the SAM. I also couldn't reproduce the problem.– Andrey Tyukin
Mar 28 at 18:37
@AndreyTyukin Thanks for the clarification, I already knew that it was not an implicit conversion, but something more low level on the compiler. However, did not know what it was. So, thanks for the info both for me and for those reading this.
– Luis Miguel Mejía Suárez
Mar 28 at 18:53
@AndreyTyukin Thanks for the clarification, I already knew that it was not an implicit conversion, but something more low level on the compiler. However, did not know what it was. So, thanks for the info both for me and for those reading this.
– Luis Miguel Mejía Suárez
Mar 28 at 18:53
This is on version 2.11. I added the
-Xexperimental
flag to my compiler options and now the second option is working as well. I wonder if I have a config mismatch or something in IntelliJ that's telling it that SAM is available by default.– pbeardshear
Mar 28 at 18:57
This is on version 2.11. I added the
-Xexperimental
flag to my compiler options and now the second option is working as well. I wonder if I have a config mismatch or something in IntelliJ that's telling it that SAM is available by default.– pbeardshear
Mar 28 at 18:57
Please check stackoverflow.com/questions/36828074/…. Looks like duplicate question.
– KZapagol
Mar 29 at 9:18
Please check stackoverflow.com/questions/36828074/…. Looks like duplicate question.
– KZapagol
Mar 29 at 9:18
|
show 2 more comments
0
active
oldest
votes
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/4.0/"u003ecc by-sa 4.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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55403844%2fscala-conversion-to-java-function-never-terminates%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55403844%2fscala-conversion-to-java-function-never-terminates%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Which version of Scala are you using? Probably the problem is that on your second example basically it seems you are calling yourself recursively... Just that, that's not true, at least since
2.12
(I believe this was introduced since2.11
, but not sure tough) that conversion already exists (I can just write this on the REL ` val jf: java.util.function.Function[String, Int] = s => s.toInt`), which probably is why Intellij suggest the change. I tested your second example on the RELP and it works too, so I am not sure what would be the problem on your case.– Luis Miguel Mejía Suárez
Mar 28 at 18:07
1
@LuisMiguelMejíaSuárez That the
s => s.toInt
is accepted asjava.util.function.Function
is not an implicit conversion, it's the SAM. I also couldn't reproduce the problem.– Andrey Tyukin
Mar 28 at 18:37
@AndreyTyukin Thanks for the clarification, I already knew that it was not an implicit conversion, but something more low level on the compiler. However, did not know what it was. So, thanks for the info both for me and for those reading this.
– Luis Miguel Mejía Suárez
Mar 28 at 18:53
This is on version 2.11. I added the
-Xexperimental
flag to my compiler options and now the second option is working as well. I wonder if I have a config mismatch or something in IntelliJ that's telling it that SAM is available by default.– pbeardshear
Mar 28 at 18:57
Please check stackoverflow.com/questions/36828074/…. Looks like duplicate question.
– KZapagol
Mar 29 at 9:18