对于类变量,向上铸造和向下铸造有什么区别?
例如,在下面的程序类中,Animal只包含一个方法但Dog类包含两个方法,那么我们如何将Dog变量转换为Animal变量.
如果完成了施法,那么我们如何使用Animal的变量调用Dog的另一种方法.
class Animal
{
public void callme()
{
System.out.println("In callme of Animal");
}
}
class Dog extends Animal
{
public void callme()
{
System.out.println("In callme of Dog");
}
public void callme2()
{
System.out.println("In callme2 of Dog");
}
}
public class UseAnimlas
{
public static void main (String [] args)
{
Dog d = new Dog();
Animal a = (Animal)d;
d.callme();
a.callme();
((Dog) a).callme2();
}
}
Run Code Online (Sandbox Code Playgroud) 当我运行我创建的应用程序时,我总是遇到错误,根据我的研究,我没有在清单中注册我的Activity.如何在AndroidManifest.xml中注册新活动?
错误信息:
android.database.sqlite.SQLiteException: near "transaction": syntax error (code 1): , while compiling: **create table transaction ( _id integer primary key autoincrement, amount real, type varchar(20), date integer)
Run Code Online (Sandbox Code Playgroud)
我的应用程序存储由自动生成的ID,花费的金额,付款类型和日期组成的货币交易.我的应用程序编译正常,但是当我尝试运行数据库是sqlite数据库的活动时,应用程序崩溃了上面的消息.至于我意识到我的SQL语句是有效的,任何人都可以提供任何可能是原因的洞察力吗?
Java代码:
db.execSQL("create table transaction (" +
" _id integer primary key autoincrement, amount real, type varchar(20), date integer)");
Run Code Online (Sandbox Code Playgroud)
谢谢
我有一个使用Java开发的Android应用程序.我现在想开始在同一个应用程序中使用Kotlin.是否可以在现有应用程序中并排使用Kotlin和Java?