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

  • SEARCH
  • Home
  • 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 6196221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:36:23+00:00 2026-05-24T03:36:23+00:00

I have 3 java files: HW.java, myAnn.java, and Constants.java in package myApp. Constants.java: public

  • 0

I have 3 java files: HW.java, myAnn.java, and Constants.java in package myApp.

Constants.java:

public final class Constants {
    public static final String WORLD ="World";
}

myAnn.java:

public @interface myAnn {
    java.lang.String name() default "";
}

HW.java:

class HW {
    @myAnn(name = Constants.WORLD)
    public static void main(String[] args){
        System.out.println("Hi "+ Constants.WORLD);
    }
}

My app compiles and runs fine as shown above, but I want to migrate HW.java to scala as
HelloWorld.scala:

object HelloWorld {
  @myAnn(name = Constants.WORLD)
  def main(args: Array[String]) {
    println("Hello " + Constants.WORLD)
  }
}

When I try to compile this, I get

error: annotation argument needs to be a constant; found:
Constants.WORLD @myAnn(name = Constants.WORLD)

If I remove the annotation then HelloWorld compiles and executes as expected.

Why can I use Constants.WORLD as a parameter to an annotation from a java program, but not from a scala program? Is there something I can modify in Constants.java to allow it to be used from either java or scala? I can’t modify MyAnn.java, and I can’t migrate Constants.java yet.

  • 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-24T03:36:24+00:00Added an answer on May 24, 2026 at 3:36 am

    It is a bug that only shows up when feeding the java source files into the scala compiler, see issue SI-2764. The example works when compiling the java files first using javac and then pointing scalac‘s classpath to the generated classfiles.

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

Sidebar

Related Questions

I have a Java program that loads thirdparty class files (classes I did not
I have a java class that applies an xslt to all xml files in
I have a Java file TestThis.java like the following: class A { public void
I have stored non-java files in a package. I want to read files from
I have two Java class files: primegen and primecheck sitting in the same directory.
I have many Java source files which I need to change their package line
I have java class files and property files in the same directory. src/main/java/com/berlin/Test.class src/main/java/com/berlin/Test.properties
I have a bunch of java files from which I want to remove the
I have a Java application that monitors a folder for incoming XML files. When
Following on from my recent question regarding parsing XML files in Java I have

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.