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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:38:31+00:00 2026-06-11T05:38:31+00:00

I have a val : val something = System.nanoTime that then goes through a

  • 0

I have a val:

val something = System.nanoTime

that then goes through a series of method calls:

foo(something) {
  bar(something, 2) { etc }
}

I’d like to defer val resolution until a very last method that actually does something with it. I’m aware of scala’s lazy modifier, but it seems that passing something as a parameter automatically resolves it’s value, regardless if the variable is being used or not inside that method.

My (somewhat ugly) solution so far is:

val something = () => System.nanoTime

Although this works, it involves changing all the method signatures, in this case from Long to () => Long. I guess there might be a more elegant way of solving it, what do you guys think?

  • 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-11T05:38:33+00:00Added an answer on June 11, 2026 at 5:38 am

    It’s not possible to do this without changing the signatures, however you should use x: => Long instead of x: () => Long. The first is a so called by name parameter. A by name parameter will be evaluated, every time you call it. So in total it would look like:

    def foo(x: => Long) = {
      x + 12 // x will be evaluated here
    }
    
    lazy val x = 12L
    foo(x)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a Map: val m = Map(foo -> 10, bar -> 5)
If we have char *val = someString; and then say if(val){ .... } what
In Django's templates system, if I have a block that I want to make
I have a script that will walk a system directory, and get the files
I have a quad processor. I coded something like that in java; Some.java; public
Something odd going on here. I have some JS that posts to a ASP.NET
If you have something like: val myStuff = Array(Person(joe,40), Person(mary, 35)) How do you
I have a string that contains ?action=a&current=b&something=c i want to create a variable that
You have: val array = new Array[Array[Cell]](height, width) How do you initialize all elements
i have this script: val.split( /(?:,.| )+/ ) and i need to split any

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.