首页 > 解决方案 > this.openOrCreateDatabase() 和 SQLiteDatabase.openOrCreateDatabase() 之间的区别

问题描述

当我遇到这个时,我正在尝试使用 android 创建一个 sqlite 数据库。

有2种方法this.openOrCreateDatabase()SQLiteDatabase.openOrCreateDatabase()

这两者有什么区别,应该使用哪一个

标签: javaandroidandroid-sqlite

解决方案


this将为您当前定义的类调用实例化对象上的方法。

SQLiteDatabase.openOrCreateDatabase()将调用SQLiteDatabase 类中定义的静态方法。

public class YourObject {
   //constructor

   public void openOrCreateDatabase() {
       //do something special
   }

   public void methodYouAreWriting() {
       this.openOrCreateDatabase() //do something special - interacts with YourObject::openOrCreateDatabase
   }

   public void methodYouAreWritingToOpenSQLiteDatabase() {
       SQLiteDatabase.openOrCreateDatabase() // Interacts with SQLiteDatabase class.
   }

推荐阅读