I use scala reflection to get information on a trait defined in my Model Class. I can easily get the members of this class doing this:
ru.runtimeMirror(myClassLoader).staticClass("model.Model").typeSignature.members
but how to know whether these members are defined or not, ie if they have an implementation or not ?
Each test method should have an "annotation" @ Test . This tells the JUnit test framework that this is an executable test method. To run the tests, select the project with the right-mouse button and click Test. Let's add functionality for adding and subtracting to the test class.
Abstract. Observation method is described as a method to observe and describe the behavior of a subject and it involves the basic technique of simply watching the phenomena until some hunch or insight is gained.
The Python's isinstance() function checks whether the object or variable is an instance of the specified class type or data type. For example, isinstance(name, str) checks if name is an instance of a class str .
Mockito verify() simple example verify(mockList, times(1)). size(); If we want to make sure a method is called but we don't care about the argument, then we can use ArgumentMatchers with verify method. verify(mockList).
Wow that's an oversight! I've submitted a pull request targetting 2.11.0 (https://github.com/scala/scala/pull/2612) that adds Symbol.isAbstract
.
Since this is a new API, due to compatibility restrictions it cannot make it into 2.10.x, so in the meanwhile please use the following workaround:
00:01 ~/Projects/210x (2.10.x)$ scala
Welcome to Scala version 2.10.3-20130527-133534-9b310bc906 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_45).
Type in expressions to have them evaluated.
Type :help for more information.
scala> trait C { def foo: Int; def bar = 2 }
defined trait C
scala> val foo = typeOf[C].declarations.toList.apply(1)
foo: reflect.runtime.universe.Symbol = method foo
scala> val bar = typeOf[C].declarations.toList.apply(2)
bar: reflect.runtime.universe.Symbol = method bar
scala> def isDeferred(sym: Symbol) = sym
.asInstanceOf[scala.reflect.internal.Symbols#Symbol]
.hasFlag(scala.reflect.internal.Flags.DEFERRED)
isDeferred: (sym: reflect.runtime.universe.Symbol)Boolean
scala> isDeferred(foo)
res2: Boolean = true
scala> isDeferred(bar)
res3: Boolean = false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With