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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:28:01+00:00 2026-06-02T19:28:01+00:00

Scenario: 1) I have a long state variable that can either be set or

  • 0

Scenario:

1) I have a long state variable that can either be set or not set.

2) This long variable has valid values from Long.MIN_VALUE to Long.MAX_VALUE including zero

3) This is performance sensitive code so I don’t want to use a Long wrapper type

How do I write an ‘is set’ kind of check for this long? Do I really have to add a second boolean value to test whether the long is valid or not? This seems sloppy. I know I could use a Long wrapper here but this seems like a performance waste to be creating so many objects and checking for null.

Pseudo Code (this is sort of what I want):

class foo {

long someLong = NaN; //NaN = hypothetical not a number like Double

public reset() {
  someLong = NaN;
}

public doSomethingElse() {
   if(someLong !=NaN) {
     //report
     reset();
   }
}

public doSomeStuff() {
  if(someLong == NaN) {
   someLong = //something
  }
}

}

}
  • 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-02T19:28:02+00:00Added an answer on June 2, 2026 at 7:28 pm

    You’d have to set aside a special value for NaN. If you really use all possible values, there is none.

    Are you sure Long objects are that much of a performance problem?

    If so, maybe have an extra boolean to denote if the value is set or not?

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

Sidebar

Related Questions

Scenario: I have a Javascript-generated web page that someone else wrote a long time
Here is my scenario: I have table A, that has 4 rows (id, col1,
How do you handle user stories/acceptance tests that have long chains like this one,
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later
Scenario: You have an ASP.Net webpage that should display the next image in a
Scenario: I have a console application that needs to access a network share with
Scenario I have recently graduated from university with a degree in Computer Science. My
Good afternoon to all, I have this scenario: I am using SQL Server 'BulkInsert'
I have some long-running operations that number in the hundreds. At the moment they
Scenario: Most smartphones have a high resolution camera that generates photos that may range

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.