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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:22:08+00:00 2026-06-11T12:22:08+00:00

The fine Twitter util library has the following Java class, which is extended by

  • 0

The fine Twitter util library has the following Java class, which is extended by a Scala class that reads the volatile field and updates it using AtomicReferenceFieldUpdater. Access must be at least private, i.e., must allow other.state.

Is the motivational claim in the comment true? How true? (“How” means in what way and to what degree.)

public class IVarField<A> {
  /** This is needed because we cannot create a field like this in Scala.  */
  volatile State<A> state;
}
  • 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-11T12:22:09+00:00Added an answer on June 11, 2026 at 12:22 pm

    Something like the following works.

    Making the field "private [this]" turns it into the desired field reference ("getfield").

    Access from a different instance is through an accessor "state()" which, if made @inline, will happily loosen the access restriction to the field.

    That also means that the updater (which happens to reside in the companion module) can also access it.

    (Because the normal accessor for the var is not emitted for an object-private member, you can define your own, using parens. But you don’t need to use parens at the call site, other.state. Your uniform access principle dollars at work. Or Swiss francs.)

    Also notice the totally hip usage of `new` in backticks for a param name. I don’t even know how to make the ticks show up in this markup. Because both params are the same type, one is likely to want to write cas(expect=prev, `new`=changed), so I might have used next instead, but if this markup supported a hipster thumbs-up, I’d give it right now. :+1: Did it work? Can anyone see my thumb? [I guess I saw that on github. Hubster, not hipster.]

    object IVar {
      // TODO: retrieve mangled name by reflection
      private final val stateField = "com$twitter$concurrent$IVar$$state"
      private val stateUpd = AtomicReferenceFieldUpdater.newUpdater(
            classOf[IVar[_]], classOf[State[_]], stateField)
    }
    
    final class IVar[A] {  //}extends IVarField[A] {
      import IVar._
    
      @volatile private[this] var state: State[A] = initState: State[A]
          
      @inline private final def state(): State[A] = this.state
              
      override def toString = "Ivar@%s(state=%s)".format(hashCode, state)
    
      @inline private[this]
      def cas(expect: State[A], `new`: State[A]) = stateUpd.compareAndSet(this, expect, `new`)
    
      def depth: Int = {
        @tailrec
        def loop(iv: IVar[_], d: Int): Int = iv.state match {
          case Linked(iv) => loop(iv, d + 1)
          case _ => d
        }
        loop(this, 0)
      }
      // etc
    }
    

    Showing that state() is really inlined:

    private final int loop$1(com.twitter.concurrent.IVar, int);
      flags: ACC_PRIVATE, ACC_FINAL
      Code:
        stack=3, locals=5, args_size=3
           0: aload_1
      // Field   com$twitter$concurrent$IVar$$state:Lcom/twitter/concurrent/ivar/State;
           1: getfield      #16                 
           4: astore_3
    

    Not only is it "OK to ask and answer your own questions",

    https://blog.stackoverflow.com/2011/07/its-ok-to-ask-and-answer-your-own-questions/

    it’s infinitely more satisfying.

    (More power to Daniel Sobral, Rex Kerr, Retronym and the rest of the Justice League.)

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

Sidebar

Related Questions

Here is a jsFiddle code that works fine if no Twitter widget was inserted
I have a piece of piece of twitter sharing codes that works fine for
I am writing a script to talk with twitter - everything seems fine apart
I have been using Twitter's Bootstrap Tooltip plugin . This works perfectly fine except
Works fine on Debug|iphone build. For Release|iphone I am getting following error: ld: duplicate
I am working on an iOS app that needs to post to either Twitter,
I am trying to make Twitter work in my app and everything works fine
I'm using twitter bootstrap modal dialog. And it works fine while only opening it
I am using MGTwitterEngine to Integrate twitter in my app.It works fine up to
A project for class involves parsing Twitter JSON data. I'm getting the data and

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.