Tag: 属性

财产获得者和制定者

有了这个简单的类,我得到的编译器警告“试图修改/访问'在自己的setter / getter”x“,当我这样使用它: var p: point = Point() px = 12 我得到一个EXC_BAD_ACCESS。 我怎样才能做到这一点没有明确的支持ivars? class Point { var x: Int { set { x = newValue * 2 //Error } get { return x / 2 //Error } } // … }

如何从Lucene TokenStream获取令牌?

我正在尝试使用Apache Lucene进行标记,而我对从TokenStream获取标记的过程感到困惑。 最糟糕的部分是我正在查看解决我的问题的JavaDoc中的注释。 http://lucene.apache.org/java/3_0_1/api/core/org/apache/lucene/analysis/TokenStream.html#incrementToken%28%29 不知何故,一个AttributeSource应该被使用,而不是Token 。 我完全不知所措 任何人都可以解释如何从TokenStream获取类似令牌的信息?

为什么JavaScript 2中的2 == ?

我最近在JavaScript中发现了2 == [2] 。 事实certificate,这个怪癖有一些有趣的结果: var a = [0, 1, 2, 3]; a[[2]] === a[2]; // this is true 同样,下面的作品: var a = { "abc" : 1 }; a[["abc"]] === a["abc"]; // this is also true 即使是陌生人,这也适用: [[[[[[[2]]]]]]] == 2; // this is true too! WTF? 这些行为在所有浏览器中都是一致的。 任何想法,为什么这是一个语言function? 以下是这个“特征”更疯狂的后果: [0] == false // true if […]

Python对象字段中的字典

你知道是否有一个内置的函数来从任意对象build立一个字典? 我想要做这样的事情: >>> class Foo: … bar = 'hello' … baz = 'world' … >>> f = Foo() >>> props(f) { 'bar' : 'hello', 'baz' : 'world' } 注意:它不应该包括方法。 只有领域。

获取DisplayName属性的值

public class Class1 { [DisplayName("Something To Name")] public virtual string Name { get; set; } } 如何获取在C#中的DisplayName属性的值?

在Objective C中创build一个整数属性数组

我在创build一个在Objective C中的整数数组属性的麻烦。我不知道这是甚至可以在Obj-C做,所以我希望有人可以帮助我找出如何做到这一点正确或提供替代解决scheme。 myclass.h @interface myClass : NSObject { @private int doubleDigits[10]; } @property int doubleDigits; @end myclass.m @implementation myClass @synthesize doubleDigits; -(id) init { self = [super init]; int doubleDigits[10] = {1,2,3,4,5,6,7,8,9,10}; return self; } @end 当我build立并运行时,我得到以下错误: 错误:属性types'doubleDigits'不匹配types的伊娃'doubleDigits' 希望有人能提供一个解决scheme或引导我在正确的方向。 提前致谢。

@Controller类中的Spring @Value批注不计算属性文件中的值

我是Spring的新手,并尝试使用@Value("${loginpage.message}")批注在带有@Controller批注的批注中注入一个带有值的string,并且我的string的值被评估为string"${loginpage.message}"而不是在我的属性文件里面。 下面是我想要注入的string“消息”的控制器。 @Controller public class LoginController extends BaseController { @Value("${loginpage.message}") private String message; @RequestMapping("/") public String goToLoginPage(Model model) { model.addAttribute("message", message); return "/login"; } } 我的应用程序上下文如下所示: <context:property-placeholder location="classpath:properties/application.properties" /> <context:annotation-config /> <context:component-scan base-package="com.me.application" /> 我的属性文件有一行: loginpage.message=this is a test message Spring必须在某个时刻获取值,因为无论何时将@Value("${loginpage.message}")更改为不属于@Value("${notInPropertiesFile}")属性文件中的值,我都会收到一个exception。

在Python中迭代对象的属性

我有一个python对象有几个属性和方法。 我想迭代对象的属性。 class my_python_obj(object): attr1='a' attr2='b' attr3='c' def method1(self, etc, etc): #Statements 我想生成一个包含所有对象属性及其当前值的字典,但我想以dynamic的方式来做(所以如果以后我添加另一个属性,我不必记得更新我的函数)。 在PHPvariables可以用作键,但python中的对象是unsuscriptable,如果我使用点符号为此它创build一个新的属性与我的变种的名称,这不是我的意图。 只是为了使事情更清楚: def to_dict(self): '''this is what I already have''' d={} d["attr1"]= self.attr1 d["attr2"]= self.attr2 d["attr3"]= self.attr3 return d · def to_dict(self): '''this is what I want to do''' d={} for v in my_python_obj.attributes: d[v] = self.v return d 更新:有了属性,我的意思是只有这个对象的variables,而不是方法。

在JAR中加载属性文件?

我遇到麻烦时,我的Web应用程序所依赖的一个jar子试图从jar中加载属性文件。 这是jar中的代码。 static { Properties props = new Properties(); try { props.load(ClassLoader.getSystemResourceAsStream("someProps.properties")); } catch (IOException e) { e.printStackTrace(); } someProperty = props.getProperty("someKey"); } 属性文件位于Maven项目的“src / main / resources”目录下。 当我在Eclipse的junittesting中运行这个代码时,它执行得很好。 当使用Maven将项目构build到jar中,并将其作为依赖项包含在webb应用程序中时,将无法find属性文件。 我知道属性文件是在依赖jar的基础目录,我不知道如何解决这个问题。 请帮忙!

为什么在entity framework模型定义中为类属性使用“虚拟”?

在以下博客中: http : //weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx 该博客包含以下代码示例: public class Dinner { public int DinnerID { get; set; } public string Title { get; set; } public DateTime EventDate { get; set; } public string Address { get; set; } public string HostedBy { get; set; } public virtual ICollection<RSVP> RSVPs { get; set; } } public class […]