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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:49:42+00:00 2026-05-22T21:49:42+00:00

If I define a Scala class: class X(i:Int) { println (i) } How do

  • 0

If I define a Scala class:

 class X(i:Int) {
   println (i)
 }

How do I use this class in Java code?

[EDIT] Actually, my problem is slightly more complicated

I have an abstract class

 abstract class X(i:Int) {
   println (i)
   def hello(s:String):Unit
 }

I need to use this in Java code. Is it possible to do it easily?

[EDIT2] Consider the following code

 object B {
    case class C(i:Int)
 }
 abstract class X(i:Int) {
   println (i)
   def hello(a:B.C):Unit
 }

In this case, the following java code gives an error in Netbeans IDE but builds fine:

 public class Y extends X  {
    public void hello(B.C c) {
       System.out.println("here");
    }
    public Y(int i) {
       super(i);
    }
 }

The error I get is:

hello(B.C) in Y cannot override hello(B.C) in X; overridden method is static, final

Netbeans 6.8, Scala 2.8.

As of now I think the only solution is to ignore the NB errors.

Here is an image showing the exact error(s) I get:
IDE error using scala code from java

  • 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-22T21:49:43+00:00Added an answer on May 22, 2026 at 9:49 pm

    The generated bytecode for your class will be identical to the Java definition:

    abstract class X implements scala.ScalaObject {
      public X(int i) {
        System.out.println(i);
      }
    
      public abstract void hello(String s);
    
      //possibly other fields/methods mixed-in from ScalaObject
    }
    

    Use it exactly as you would for this equivalent Java; subclass and provide a concrete implementation of the hello method.

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

Sidebar

Related Questions

Consider this simple Scala class: class A(val d: Int) Is there a difference in
Is there a nicer way of doing this? scala> case class A(x : Int)
Say you define the following: class Person(name: String, age: Int) { def toXml =
I have this case class define: class Protocol(protocol:String) object Protocol { def apply(protocol:String) :Protocol
In Scala, I can make a caseclass, case class Foo(x:Int) , and then put
I tagged this question both Java and Scala because while I mainly develop on
I have this domain object: case class Person ( name : String, age: Option[Int],
Simple question, I have code like this: class Context[A] { def t: A }
In Scala, if I define a method called apply in a class or a
This works def func(f: => Int) = f This dosn't (inside class for example)

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.