title: How to access a typecasted object's method directly?
body: <p>This looks like a basic object oriented problem, but I was coming from Pascal / Delphi background, and I can't find the similar method to get the same result in Java.</p>
  
  <p>In Pascal/Delphi, I can change something like this (this is not entirely correct, but just to give you an illustration):</p>
  
  <pre><code>var a: TButton; b: string;
  begin
    a := TButton(getObject(request));
    b := a.caption;
  end;
  </code></pre>
  
  <p>into this:</p>
  
  <pre><code>var b: string;
  begin
    b := TButton(getObject(request)).caption;
  end;
  </code></pre>
  
  <p>But how to achieve the same solution in Java? how to change:</p>
  
  <pre><code>Button a;
  String b;
  a = (Button) getObject(request);
  b = a.caption;
  </code></pre>
  
  <p>into</p>
  
  <pre><code>String b;
  b = (Button) getObject(request).caption;
  </code></pre>
  
  <p>or something like that? The point is, I want to eliminate the need of declaring temporary variable to hold an object, if what I want is just to take another value (or object) inside that object. But the problem is, the object need to be typecasted first because all I receive is just a general Object from the <code>getObject()</code> function. Thanks for your help.</p>