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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:14:18+00:00 2026-06-12T18:14:18+00:00

Is it possible to make Scala (or Java called from Scala) check whether a

  • 0

Is it possible to make Scala (or Java called from Scala) check whether a resource is missing at compile time and throw a compile error if it’s missing?

I’m working on a large Java/Scala hybrid project with many developers and I’m providing a Scala component that kicks in near the end of the system run. So if my component throws a missing resource runtime error, it’s only discovered very late. I try to make sure that my resource is there so this doesn’t happen. But several times already, the head engineer decided to shift things around, my resources changed paths, I wasn’t aware so didn’t change my code, then the code died at my component because of the missing resource. We’re working on more centralized resource control, but in the meantime, would it be possible to make Scala throw a compile error over a missing resource? Mostly curiosity, but might implement if it turns out simple enough.

ETA: There’s questions about build tools. It’s not straightforward because everyone is using their own environment. Some are using eclipse, some netbeans, I’m using emacs+sbt. So even if I insert a check for sbt, it won’t matter to other people who are using eclipse.

  • 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-06-12T18:14:20+00:00Added an answer on June 12, 2026 at 6:14 pm

    In 2.10, it is definitely possible with help of a macro and string interpolation:

    object CheckResource {
    
      import scala.reflect.macros.Context
      import scala.language.experimental.macros
    
      implicit class StringResource(sc: StringContext) {
        def res(): String = macro __res
      }
    
      def __res(c: Context)(): c.Expr[String] = {
        import c.universe._
        val str = c.prefix.tree match {
          case Apply(_, List(Apply(_, List(Literal(Constant(const: String)))))) =>
            if (!new java.io.File(const).exists())
              c.abort(c.enclosingPosition, s"file '$const' does not exist")
            else Literal(Constant(const))
        }
        c.Expr(str)
      }
    }
    
    scala> import CheckResource._
    import CheckResource._
    
    scala> val file = new java.io.File("test")
    file: java.io.File = test
    
    scala> file.createNewFile
    res7: Boolean = true
    
    scala> res"test"
    res8: String = test
    
    scala> file.delete
    res9: Boolean = true
    
    scala> res"test"
    <console>:12: error: file 'test' does not exist
                  res"test"
                  ^
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Make error: missing separator I am so stressed out by this silly
Possible Duplicate: Make iPhone app paid version replace free version on install from app
Is it possible in Scala to make some mixin to class instance? Eg: I
Is it possible to make an alias for item of an array in scala?
I'm working to learn Scala--coming from a C++ background. I am trying to write
If I wanted my Scala project to be compatible with Java, that is make
I'm new to Scala (from Java) and I like to develop TDD/BDD. So before
Is it possible make some handler that will do something when user shutdown computer
Is it possible make an activity, that will lock the android device? That device
is possible to make own help message or attach own event on help option

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.