Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6614749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:22:36+00:00 2026-05-25T20:22:36+00:00

Here at work most people use Java, while I am working with Scala. We

  • 0

Here at work most people use Java, while I am working with Scala. We have decided to gather some common classes in an library which will be written in Java. Now I want to add some pseudo-functional programming to the library, take a look at the following:

java:

public interface Func<A, R> {
    public R f(a A);
}

public AClass {
    public <R> ArrayList<R> myMethod(
                             Func<String, R> func
    ) {
        // ...
    }
}

usage in java:

AClass ac = new AClass();
ArrayList<String> al = ac.myMethod(
                            new Func<String, String> (
                                public String f(String s) {
                                    return s + "!";
                                }
                            })

The above is not exactly exiting (more like daunting actually, from a scala perspective). Is there any way to summon some scala magic to be able to do something like the following in scala:

var ac = new ACLass
var al = ac.myMethod(str => str + "!")             // alternative 1
al = ac.myMethod { case: str:String => str + "!" } // alternative 2

I messed around with implicits for a while but couldn’t get things sorted out =P.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:22:36+00:00Added an answer on May 25, 2026 at 8:22 pm

    With implicit conversions:

    object FuncConversions {
      implicit def func2function[A,R]( fn: (A) => R ) =
        new Func[A,R] {
          def f(a: A) = fn(a)
        }
    }
    

    Don’t forget to import the conversion in your scope:

    import FuncConversions._
    

    You can also implement the opposite conversion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have decided to work with the Insert Framework Here We'll most likely update
Here at work, we are working on a newsletter system that our clients can
Here at work we have a very large application with multiple sub applications. (500
At work here, we have a box serving XML feeds to business partners. Requests
I've got a few controllers here at work that contain methods I can use
The way I see most people use Processing is for drawing an image directly
I work on an engineering team of 4 people, mostly writing javascript while occasionally
I wanted to learn Java, as recommended by most of the people I downloaded
Here at work, we often need to find a string from the list of
We had a discussion here at work regarding why fread() and fwrite() take a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.