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 7696385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:46:02+00:00 2026-05-31T21:46:02+00:00

I have a Scala/Java dual language project where I need to pass a Scala

  • 0

I have a Scala/Java dual language project where I need to pass a Scala enumeration from Java.

object MonthSelection extends Enumeration {
   type MonthSelection = Value

   val LastMonth, ThisMonth, NextMonth, CustomMonth = Value
}

class MyClass {

   def doDateStuff(monthChosen: MonthSelection) = {
   // do stuff
   }
}

How do I call this from Java? I am getting a compile error as I cannot seem to import scala.Enumeration.Value.

   MyClass myClass = new MyClass();
   myClass.doStuff(MonthSelection.ThisMonth);
  • 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-31T21:46:03+00:00Added an answer on May 31, 2026 at 9:46 pm

    When in doubt, look at the generated bytecode. 🙂

    $> cat foo.scala
    object MonthSelection extends Enumeration {
        type MonthSelection = Value
    
        val LastMonth, ThisMonth, NextMonth, CustomMonth = Value
    }
    
    $> scalac -d bin foo.scala
    $> ls bin
    MonthSelection$.class  MonthSelection.class
    $> javap bin/MonthSelection
    Compiled from "foo.scala"
    public final class MonthSelection extends java.lang.Object{
        public static final scala.Enumeration$Value CustomMonth();
        public static final scala.Enumeration$Value NextMonth();
        public static final scala.Enumeration$Value ThisMonth();
        public static final scala.Enumeration$Value LastMonth();
        public static final scala.Enumeration$ValueSet$ ValueSet();
        public static final scala.Enumeration$Value withName(java.lang.String);
        public static final scala.Enumeration$Value apply(int);
        public static final int maxId();
        public static final scala.Enumeration$ValueSet values();
        public static final java.lang.String toString();
    }
    

    Ok, easy. All of these enumerations are public static methods. I just have to import scala.Enumeration and directly invoke these methods.

    $> cat Some.java
    import scala.Enumeration;
    
    public class Some {
        public static void main(String args[]) {
            System.out.println("Hello!");
            System.out.println(MonthSelection.CustomMonth());
        }
    }
    
    $> javac -cp $SCALA_HOME/lib/scala-library.jar:bin/ -d bin Some.java
    $> ls bin
    MonthSelection$.class  MonthSelection.class  Some.class
    $> java -cp $SCALA_HOME/lib/scala-library.jar:bin Some              
    Hello!
    CustomMonth
    

    Hope this gives you more ideas to play with. 🙂

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

Sidebar

Related Questions

I'm trying to write a large scale project in Java/Scala(a JVM language) that extends
I have a project with mixed Java and Scala sources, following the instructions on
I have a Scala project in Eclipse that I need to package up so
For a java/scala project I have some dependencies that are not in a remote
We have a Scala project with few source files (in Scala and Java) and
We have a mixed Java and Scala project, which uses Spring transaction management. We
I'm migrating an app from java to Scala. In java I have somethng like
I have read that Scala's type system is weakened by Java interoperability and therefore
I have an application where I would like to have mixed Java and Scala
On large-scale Java/.Net Enterprise projects, does every developer need to have all the components/libraries/dependencies

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.