title: Get all fields from anonymous class in Scala
body: <p>I want to get all fields from class instance through reflection. All works fine for ordinary classes (filter only for example):</p>
  
  <pre><code>scala&gt; import scala.reflect.runtime.universe._
  scala&gt; import scala.reflect.runtime.currentMirror
  scala&gt; class A {val a = 1}
  scala&gt; currentMirror.classSymbol((newA).getClass).toType.members.filter(_.name.toString == "a")
  res12: Iterable[reflect.runtime.universe.Symbol] = SynchronizedOps(value a)
  </code></pre>
  
  <p>But in case of anonymous classes I have different situation:</p>
  
  <pre><code>scala&gt; trait B {val b = 2}
  scala&gt; currentMirror.classSymbol((new B {}).getClass).toType.members.filter(_.name.toString == "b")
  res13: Iterable[reflect.runtime.universe.Symbol] = SynchronizedOps(method b, value b)
  </code></pre>
  
  <p>This value is not public, but method is public. Can somebody explain, what's happening here? Why in case of anonymous class I don't have simple public <code>value b</code>? Is there any workaround for uniform members handling?</p>
  
  <p>EDIT</p>
  
  <p>Actually, my original task is to <em>get all public fields from any instance</em>. In case of ordinary classes I use this code:</p>
  
  <pre><code>val reflectedInstance = currentMirror.reflect(instance)
  for {
    member ← reflectedInstance.symbol.toType.members
    if member.isPublic &amp;&amp; (!member.isMethod || member.asMethod.isGetter)
  } yield //do something
  </code></pre>
  
  <p>Example above describes, why this code is not working in case of anonymous classes. So, now I'm looking for some way, how to get all public fields from both ordinary and anonymous classes.</p>