标签: instance

iphone EXC_BAD_ACCESS使用我自己的类

我创建了自己的类,由NSObject派生,这是我的代码:

-(void) parseRow:(NSDictionary*) dictionary {
    NSArray* arName = [[dictionary valueForKey:displayname] componentsSeparatedByString:@"+"];
    [self setDriverName:[arName objectAtIndex:0]];
    [self setDriverSurname:[arName objectAtIndex:1]];
    [arName release]; // this give problem!
}
Run Code Online (Sandbox Code Playgroud)

在我看来:

driverStats = [[DriverStats alloc] init];

// driverStats is declared in the header:
DriverStats* driverStats;
@property (nonatomic,retain) DriverStats* driverStats;

[driverStats parseRow:dictionary];
Run Code Online (Sandbox Code Playgroud)

如果我在我的类中添加[arName release],当我从parseRow方法退出时,我有EXC_BAD_ACCESS错误....但是它错了?我使用数组并在我发布之后...我认为错误将是如果我没有释放指针..或不?提前致谢

iphone exc-bad-access class objective-c instance

0
推荐指数
1
解决办法
150
查看次数

函数可以是Haskell中的类的实例

class A a
instance A (Int -> Float)
Run Code Online (Sandbox Code Playgroud)

不起作用

class B b
instance B Int
Run Code Online (Sandbox Code Playgroud)

如果将Haskell中的函数作为第一个类并且(Int - > Float)无疑是一个类型,尽管它不是(*)具体类型,为什么函数不能成为类的实例

haskell types class function instance

0
推荐指数
1
解决办法
131
查看次数

使用现有实例(如果使用相同的值构造)

我必须创建一个允许以下内容的类/构造函数:

Object a = new Object("test");
Object b = new Object("test");

a == b // should be true
Run Code Online (Sandbox Code Playgroud)

所以对象a和b不仅应该根据它们的值相同,而且应该使用相同的引用并引用相同的内存.

构造函数应该查明具有给定值的实例是否已经存在,如果是,则只需获取引用并将其指向现有对象.

有没有办法获得特定类的所有创建实例?有人可以给我一个简短的提示从哪里开始?我不知道...

java constructor reference instance inner-classes

0
推荐指数
1
解决办法
238
查看次数

实例集合的意外行为

例如,我有以下类:

class Person
{
    public List<int> Grades{ get; set; }

    public Person(List<int> grades)
    {
        this.Grades = grades;
    }
}
Run Code Online (Sandbox Code Playgroud)

而且我在主方法中使用这个类,比如:

    static   void Main(string[] args)
    {
        List<int> grades = new List<int> { 1, 2, 3, 4, 5 };
        Person person = new Person(grades);

        for (int i = 0; i < 5; i++)
        {
            if (i % 2 == 0)
            {
                grades[i] = 0;
            }
            else
            {
                grades[i] = -1;
            }
        }

        foreach(var grade in person.Grades)
        {
            Console.Write(grade + " ");
        } …
Run Code Online (Sandbox Code Playgroud)

.net c# collections instance

0
推荐指数
1
解决办法
68
查看次数

Haskell:`=='不是(可见)类的方法

所以,当我编译下面编辑的代码时:

instance (Eq a) => PartOrd a where 
        [] == []         = True
        (x:xs) == (y:ys) = x==y && xs==ys
        _ == _           = False
        xs /= ys         = not (xs == ys)
Run Code Online (Sandbox Code Playgroud)

我明白了:

  `==' is not a (visible) method of class 'PartOrd'

  `/=' is not a (visible) method of class 'PartOrd'
Failed, modules loaded: none.
Run Code Online (Sandbox Code Playgroud)

我已经看过如何在Haskell中正确实例化类?有些澄清,但即使我无法解决它.

另外,当我使用=~for ==/~for 等定制运算符时,它是否相同/=,因为我得到了同样的错误?

编辑:根据要求:

class Eq a => PartOrd a where …
Run Code Online (Sandbox Code Playgroud)

haskell compiler-errors equality instance typeclass

0
推荐指数
1
解决办法
3406
查看次数

Guava映射存储类实例作为键和int值

我试图用番石榴的集合来创建地图,将一个类实例存储的密钥和一个整数作为值.所以像这样:

核心价值

FooOne - 1
FooTwo - 2
FooThree - 3
FooFour - 4
Run Code Online (Sandbox Code Playgroud)

我现在在代码中有这个:

private ClassToInstanceMap<Object> classRanking = MutableClassToInstanceMap.create();
classRanking.put(FooOne.class, 0);
classRanking.put(FooTwo.class, 1);
classRanking.put(FooThree.class, 2);
classRanking.put(FooFour.class, 3);
Run Code Online (Sandbox Code Playgroud)

但是在运行时会抛出错误:

java.lang.ClassCastException: Cannot cast java.lang.Integer to com.jer.abc.test.FooOne
    at java.lang.Class.cast(Unknown Source)
    at com.google.common.collect.MutableClassToInstanceMap.cast(MutableClassToInstanceMap.java:82)
    at com.google.common.collect.MutableClassToInstanceMap.access$000(MutableClassToInstanceMap.java:36)
    at com.google.common.collect.MutableClassToInstanceMap$1.checkKeyValue(MutableClassToInstanceMap.java:67)
    at com.google.common.collect.MutableClassToInstanceMap$1.checkKeyValue(MutableClassToInstanceMap.java:64)
    at com.google.common.collect.MapConstraints$ConstrainedMap.put(MapConstraints.java:313)
    at com.fmr.gps.web.support.PortfolioInsightsSupport.populateRankingMap(PortfolioInsightsSupport.java:33)
    at com.fmr.gps.web.support.PortfolioInsightsSupport.<init>(PortfolioInsightsSupport.java:29)
    at com.fmr.gps.web.PortfolioInsightsSupportTest.setUp(PortfolioInsightsSupportTest.java:38)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) …
Run Code Online (Sandbox Code Playgroud)

java dictionary class instance guava

0
推荐指数
1
解决办法
284
查看次数

AWS Key Pair丢失了如何恢复

  • 我丢失了EC2 Instance密钥对,无法从AWS管理控制台再次下载.

  • 请告诉我如何以最简单的方式再次连接同一个实例?

instance amazon-ec2 amazon-web-services aws-cli

0
推荐指数
2
解决办法
1526
查看次数

C#Reflection,设置null属性的新实例

我编写了一个小方法,其唯一目的是检查给定类的属性是否为null.如果属性为null,则创建它的新实例.我实际上已经设置了一个值,我被卡住了:

  public static void CheckIfPropertyIsNull<TEntity>(SomeBusinessEntity someBusinessEntity) where TEntity : new()
    {
        var properties = typeof(SomeBusinessEntity).GetProperties();

        foreach (PropertyInfo propertyInfo in properties)
        {
            Type currentType = propertyInfo.PropertyType;
            if (currentType == typeof(TEntity))
            {
                var propertyData = propertyInfo.GetValue(someBusinessEntity, null);
                if (propertyData == null)

                {
                    object instance = Activator.CreateInstance(typeof(TEntity));

                    // And then?
                    //propertyInfo.SetValue(null, instance);

                    return;
                }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

我尝试使用SetValue()方法,但没有运气.

c# reflection null instance

0
推荐指数
1
解决办法
112
查看次数

为什么调用此方法会出现错误"Unbound method ... instance as first arg"?

class stack:
    def __init__(self):
        self.st = []
    def push(self, x):
        self.st.append(x)
        return self
    def pop(self):
        return self.st.pop()
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我为什么我不能运行python并执行stack.push(3)而不会得到未绑定的错误.我做了以下事情

>>> from balance import *
>>> stack.push(3)
Traceback (most recent call last):File "<stdin>", line 1, in <module>
TypeError: unbound method push() must be called with stack instance as first argument (got int instance instead)
>>> 
Run Code Online (Sandbox Code Playgroud)

但是当我编写这段代码时,我可以毫无错误地推送到堆栈:

import sys

k = sys.argv[1]

class stack:
    def __init__(self):
        self.st = []
    def push(self, x):
        self.st.append(x)
        return self
    def pop(self):
        return self.st.pop()
    def isEmpty(self):   #added an …
Run Code Online (Sandbox Code Playgroud)

python methods class instance typeerror

0
推荐指数
1
解决办法
53
查看次数

防止实例化和继承Java类

我被要求修改一个简单的类,以使其无法实例化和继承。我对于如何使用abstract而不被实例化以及final而不被继承感到困惑。

我应该怎么写这样的课?

提前致谢。

java inheritance instance

0
推荐指数
2
解决办法
84
查看次数