如果您对未绑定的方法f感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于未绑定的方法f的详细内容,我们还将为您解答必须以fibo_实例作为第一个参数来调用的相关问题,并且为您提
如果您对未绑定的方法f感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于未绑定的方法f的详细内容,我们还将为您解答必须以fibo_实例作为第一个参数来调用的相关问题,并且为您提供关于Android Java objModelClass.getClass().getDeclaredFields()返回“$change”作为一个字段、angular – 为什么[class.someClass]和[ngClass]绑定与myObservable $|的工作方式不同异步?、c# – 将Class的实例作为参数传递给Attribute构造函数、Cannot subclass a class with objc_subclassing_restricted attribute的有价值信息。
本文目录一览:- 未绑定的方法f()必须以fibo_实例作为第一个参数来调用(取而代之的是class classobj实例)
- Android Java objModelClass.getClass().getDeclaredFields()返回“$change”作为一个字段
- angular – 为什么[class.someClass]和[ngClass]绑定与myObservable $|的工作方式不同异步?
- c# – 将Class的实例作为参数传递给Attribute构造函数
- Cannot subclass a class with objc_subclassing_restricted attribute
未绑定的方法f()必须以fibo_实例作为第一个参数来调用(取而代之的是class classobj实例)
在Python中,我尝试在类中运行方法,但出现错误:
Traceback (most recent call last): File "C:\Users\domenico\Desktop\py\main.py", line 8, in <module> fibo.f() TypeError: unbound method f() must be called with fibo instance as first argument (got nothing instead)
代码:(swineflu.py)
class fibo: a=0 b=0 def f(self,a=0): print fibo.b+a b=a; return self(a+1)
脚本main.py
import swinefluf = swineflufibo = f.fibofibo.f() #TypeError is thrown here
这个错误是什么意思?是什么导致此错误?
答案1
小编典典好的,首先,您不必使用不同的名称来引用模块。您已经有一个参考(来自import
),您可以使用它。如果您想使用其他名称,请使用importswineflu as f
。
其次,您将获得对该类的引用,而不是实例化该类。
所以这应该是:
import swineflufibo = swineflu.fibo() # get an instance of the classfibo.f() # call the method f of the instance
甲 绑定的方法 是一个被附加到对象的实例。的 未结合的方法 是,当然,一个是 未
附连到一个实例。该错误通常意味着您是在类而不是实例上调用方法,这正是在这种情况下发生的事情,因为您没有实例化该类。
Android Java objModelClass.getClass().getDeclaredFields()返回“$change”作为一个字段
奇怪的是,在Android工作室中没有这样的问题但是当我们升级到android studio 2.0时就发生了这种情况.
虽然我已经应用了快速修复,但我需要正确解决这个问题.
我想知道它为什么会发生?
这个函数使用这个方法
public void insertValuesIntoTable(final String strTableName,ArrayList<Object> alObjClasses,String strPrimaryKey,String strCompositeKey) { try { sqliteDatabase db_w = this.getWritableDatabase(); ContentValues contentValues = new ContentValues(); //Iterate through every model class Object in the ArrayList and transfer the contents to the DB if (alObjClasses != null) for (Object objModelClass : alObjClasses) { for (Field field : objModelClass.getClass().getDeclaredFields()) { //Encrypt value if encryption is enabled & the column is to be encrypted try { field.setAccessible(true); //Test if the table received is Ignore contacts. Minor Hack inserted //So that the same contact data model can be re used. It checks if the //Table is of ignored constant or not then checks if the column exists //in the table or not as that of the field name. Doing this saves //from receiving a sqlConstraint exception stating,"Column not found" if(field.getName().equals("$change")) continue; if(strTableName.equalsIgnoreCase(ContactConstants.TABLE_IGnorED_CONTACTS)) if(!field.getName().equalsIgnoreCase(ContactConstants.TABLE_IGnorED_CONTACTS_NAMES) && !field.getName().equalsIgnoreCase(ContactConstants.TABLE_IGnorED_CONTACTS_NUMBERS) && !field.getName().equalsIgnoreCase(ContactConstants.TABLE_IGnorED_CONTACTS_EMAIL) && !field.getName().equalsIgnoreCase(ContactConstants.TABLE_IGnorED_CONTACTS_CITY) && !field.getName().equalsIgnoreCase(ContactConstants.TABLE_IGnorED_CONTACTS_ID)) continue; contentValues.put(field.getName(),(Constants.ENCRYPTION_PREFERENCE && HelperFunctions.isColumnEncrypted(field.getName())) ? HelperFunctions.encryptString((String) field.get(objModelClass)) : (String) field.get(objModelClass)); } catch (illegalaccessexception e) { // e.printstacktrace(); //Never thrown since field.setAccessible(true); is called before accessing data } catch ( ClassCastException e) { // e.printstacktrace(); //Never thrown since field.setAccessible(true); is called before accessing data } } try { if (db_w.insert(strTableName,null,contentValues) == -1) throw new sqliteConstraintException(); } catch (sqliteConstraintException e) { // e.printstacktrace(); Log.i("Error - DB","Error occurred while trying to add data to " + strTableName + " Table,updating data instead."); //Since the entry exists in the DB,it will be updated instead updateEntryInDatabase(db_w,strTableName,strPrimaryKey,strCompositeKey,contentValues); } } db_w.close(); } catch (NullPointerException e) { // e.printstacktrace(); //Is thrown sometimes when the context of the activity which called it is destroyed mid execution } catch (sqliteException e) { // e.printstacktrace(); //Is thrown sometimes when the context of the activity which called it is destroyed mid execution } }
解决方法
这个问题可以通过使用isSynthetic()方法检查字段来解决:它将为运行时生成的字段返回true,如$change,否则返回false.
angular – 为什么[class.someClass]和[ngClass]绑定与myObservable $|的工作方式不同异步?
< li * ngFor =“让activeRooms $| async的房间”[class.active] =“room.name ===(currentRoomName $| async)”>
我发现,如果我使用[ngClass]代替它,它完美地工作:
< li * ngFor =“让activeRooms $| async的房间”[ngClass] =“{active:room.name ===(currentRoomName $| async)}”>
这是为什么?任何人都可以对此有所了解吗?
谢谢!
解决方法
>将Observable改为EventEmitter,它们的表现略有不同;您可以阅读here以获取更多信息.
>可以在角度ngzone之外的某处生成可观察事件;在这种情况下,您需要将其注入组件并通过以下方式更新您的属性:
zone.run(()=> this.prop = newValue);
这样,角度就会看到你不会看到的变化.您可以在此处阅读有关区域的更多信息:another link
c# – 将Class的实例作为参数传递给Attribute构造函数
public class LoginModel { [AutoComplete(currentInstance)] //pass instance of class or CompanyNames public string DepartmentName { get; set; } public string[] DepartmentNames { get {...} } }
有没有办法这样做,而不使用new()或Reflection.
解决方法
另一方面,属性总是被反射消耗,所以我猜当时你正在检查这个自定义属性在类元数据上的存在,你可以使用该实例.
Cannot subclass a class with objc_subclassing_restricted attribute
Unfortunately, that is the case. You cannot subclass a Swift class (even if it is a subclass of NSObject and available to the Objective-C runtime) because of deliberate limitations baked into Obj-C to block subclassing Swift classes in Obj-C code.
I believe the reason for this limitation is that Swift includes features that cannot be utilised in Obj-C and therefore subclasses would be restricted and would get undefined behavIoUr when implementing methods that cannot cross into Obj-C.
If Apple were to allow Obj-C -> Swift -> Obj-C subclassing, then it would be on a limited basis. Some methods wouldn’t do the same thing in Swift as they would in Obj-C selectors, and you Could theoretically declare conflicting methods in your subclass that would have different actions depending on whether you were addressing the class in Swift and Obj-C. Additionally, the Swift Compiler Couldn’t see beyond the Swift barrier and therefore may make optimisations that would break your Obj-C subclasses.
While I understand the frustration behind this, both in personal projects and philosophically, I think that this is unfortunately the better of the two options.
摘自:https://forums.swift.org/t/cannot-subclass-a-class-with-objc-subclassing-restricted-attribute/5674
结论:OC里无法继承Swift类,即使Swift是@objc open 修饰也不行。(2021.07.18 记录)
关于未绑定的方法f和必须以fibo_实例作为第一个参数来调用的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于Android Java objModelClass.getClass().getDeclaredFields()返回“$change”作为一个字段、angular – 为什么[class.someClass]和[ngClass]绑定与myObservable $|的工作方式不同异步?、c# – 将Class的实例作为参数传递给Attribute构造函数、Cannot subclass a class with objc_subclassing_restricted attribute的相关知识,请在本站寻找。
本文标签: