title: Passing method as a parameter - Is this possible?
body: <p>I am trying to migrate to java 8 and have a number of methods in my dao classes which do the following</p>
  
  <pre><code>@Override
  @SuppressWarnings("unchecked")
  public List&lt;Group&gt; getGroups()
  {
      Session session = sessionFactory.openSession();
      List&lt;Group&gt; allGroups = (List&lt;Group&gt;)session.createQuery("from Group").list();
      session.close();
      return allGroups;
  }
  </code></pre>
  
  <p>Here the same boiler plate <code>sessionFactory.open</code> and <code>session.close</code> is repeated for all methods.</p>
  
  <p>Is it possible in Java 8 to have a method which does the open and close and takes a function which is the rest of my code and execute it inbetween? </p>
  
  <p>If so - what is the name of this process , or can anyone provide some help on how this might be achieved</p>