title: JavaFX Treeview return selected items
body: <p>I'd like to get the selection in a TreeView and have the corresponding model object returned. All answers about this suggest that this done with an inner class or lambda expression. However, when I do this compiler reminds me that variables have to be (effectively) final. I understand, why that is so, but I do not know solve the issue.</p>
  
  <p>Note: I'm actually not sure, why the situation would require a listener in the first place, as I don't even want to listen constantly but get the result, when the method is called.</p>
  
  <pre><code>    private CampaignObject getLeadSelect(){
      CampaignObject co = null;
  
      campTree.getSelectionModel().selectedItemProperty().addListener(
          new ChangeListener&lt;TreeItem &lt;CampaignObject&gt;&gt;() {
              @Override
              public void changed(ObservableValue&lt;? extends TreeItem&lt;CampaignObject&gt;&gt; observableValue, 
                      TreeItem&lt;CampaignObject&gt; oldItem, TreeItem&lt;CampaignObject&gt; newItem) {
                      co = newItem.getValue());
          }
      });
  
      return co;
  }
  </code></pre>