traits

Methods in trait become volatile methods when mixed in concrete classes in 2.9.0-1 but not 2.8.1

此生再无相见时 提交于 2019-12-05 17:14:44
I noticed this breaking (for me using it with OGNL) change in 2.9.0-1: I find that, in 2.9, methods declared in a trait become volatile when mixed in a class: Example in 2.9.0-1 import java.lang.reflect.Modifier trait SuperTrait { def getKnoll = "Kanutten" } class KlassWithKnoll extends SuperTrait { def getKnall = "Mars" } val qsc = classOf[KlassWithKnoll] val knollGetter = qsc.getDeclaredMethod("getKnoll") println("isVolatile: " + Modifier.isVolatile(knollGetter.getModifiers())) This prints out isVolatile: true But in 2.8.1: it prints out isVolatile: false This is actually a breaking change

PHP Traits: How to resolve a property name conflict?

為{幸葍}努か 提交于 2019-12-05 17:02:19
How to resolve a property name conflict when a class uses two Traits with homonymous properties ? Example: <?php trait Video { public $name = 'v'; } trait Audio { public $name = 'a'; } class Media { use Audio, Video; } $media = new Media(); $media->name; I've tried insteadof ( Video::name insteadof Audio ) and ( Video::name as name2 ) without success. Thanks in advance ! You can't, its for methods only. However they may use the same property name only if the value is the same: trait Video { public $name; function getName(){ return 'Video'; } } trait Audio { public $name; function getName(){

AbstractMethodError when mixing in trait nested in object - only when compiled and imported

自作多情 提交于 2019-12-05 15:51:31
Consider the following code: object Impls { trait ConcreteImpl { type Foo = Int def foo = 1 } } trait Base { type Foo def foo: Foo } I am interested in the expression (new Base with Impls.ConcreteImpl).foo When I paste the above code in the REPL, or run it in a worksheet, and then try the expression -- no problem, it prints res0: Int = 1 , as expected. When I put the code in a file, compile it with scalac , and then use the compiled class files from the REPL in the same directory, I get the same result. However , when I use the compiled files, and then say from the REPL import Impls._ (new

PHP type-hinting traits

你。 提交于 2019-12-05 12:00:13
问题 I have a trait. For the sake of creativity, let's call this trait Trait: trait Trait{ static function treat($instance){ // treat that trait instance with care } } Now, I also have a class that uses this trait, User. When trying to call treat with an instance of User, everything works. But I would like to type-hint that only instances of classes using Trait should be given as arguments, like that: static function treat(Trait $instance){...} Sadly, though, this results in a fatal error that

When extending a trait within a trait, what does 'super' refer to?

痞子三分冷 提交于 2019-12-05 11:39:36
问题 I want to to extend a trait within a trait, like this: trait NodeTypes { trait Node { def allNodesHaveThis: Int } } trait ScrumptiousTypes extends NodeTypes { trait Node extends super.Node { def scrumptiousness: Int } } trait YummyTypes extends NodeTypes { trait Node extends super.Node { def yumminess: Int } } object Graph extends NodeTypes with ScrumptiousTypes with YummyTypes { case class Node() extends super.Node { override def allNodesHaveThis = 1 override def scrumptiousness = 2 // error

PHP Class Using Same Name as Trait Function

女生的网名这么多〃 提交于 2019-12-05 10:49:19
I have the following code as a sample. trait sampletrait{ function hello(){ echo "hello from trait"; } } class client{ use sampletrait; function hello(){ echo "hello from class"; //From within here, how do I call traits hello() function also? } } I could put all the details as to why this is necessary but I want to keep this question simple. Extending from the class client is not the answer here due to my particular situation. Is it possible to have a trait have the same function name as the class using it, but call the traits function in addition to the classes function? Currently it will

c++ check for nested typedef of a template parameter to get its scalar base type

删除回忆录丶 提交于 2019-12-05 10:46:34
Consider the exponential smoother template class below. This class is for smoothing/filtering sequential data exponentially (see update method). Elemtype might be an vector and Floattype is usually a scalar. E.g. ExponentialSmoother<Eigen::Vector2f, float> x(0.1, Vector2f(0.5, 0.5)); In this example the second template parameter Floattype could be avoided because Eigen's Matrix class contains a nested typedef to get the scalar base type: Vector2f::Scalar It is also reasonable to instantiate both Elemtype and Floatype as floats to smooth one dimensional data. In this case the second template

Mysterious lifetime issue while implementing trait for dyn object

↘锁芯ラ 提交于 2019-12-05 10:14:23
问题 Consider the following toy example: use std::cmp::Ordering; pub trait SimpleOrder { fn key(&self) -> u32; } impl PartialOrd for dyn SimpleOrder { fn partial_cmp(&self, other: &dyn SimpleOrder) -> Option<Ordering> { Some(self.cmp(other)) } } impl Ord for dyn SimpleOrder { fn cmp(&self, other: &dyn SimpleOrder) -> Ordering { self.key().cmp(&other.key()) } } impl PartialEq for dyn SimpleOrder { fn eq(&self, other: &dyn SimpleOrder) -> bool { self.key() == other.key() } } impl Eq for SimpleOrder

Why is Fn derived from FnMut (which is derived from FnOnce)?

老子叫甜甜 提交于 2019-12-05 09:44:33
If you look in the official Rust doc , you see that the trait Fn is derived from FnMut , or, to implement Fn , you have to implement FnMut (and after that FnOnce since FnMut also derives from it). Why is that so? I simply can't comprehend that. Is it because you can call every Fn as a FnOnce or FnMut ? The best reference for this is the excellent Finding Closure in Rust blog post. I'll quote the salient part: There’s three traits, and so seven non-empty sets of traits that could possibly be implemented… but there’s actually only three interesting configurations: Fn , FnMut and FnOnce , FnMut

Delaying trait initialization

做~自己de王妃 提交于 2019-12-05 09:16:20
I need a smart mechanism for component composition which allows mixed in traits to initialize after the composed component. The following throws a NullPointerException : class Component { def addListener(pf: PartialFunction[Any, Unit]) {} } trait DynamicComponent { protected def component: Component component.addListener { case x => } } class Foo extends DynamicComponent { protected val component = new Component } new Foo // -> NullPointerException The following things are not options for me: Using protected lazy val component ; that would produce an avalange of dozens of vals needing to