大多数人问我最熟悉的java / c ++。
答案 0 :(得分:1)
在Java中,某些类型信息在运行时保留。这就是为什么您可以获得ArrayList<String>
的原因。但是,并非全部。特别是,Java中的泛型使用类型擦除来实现,这意味着在运行时,ArrayList<Integer>
看起来像HashSet<String>
(尽管看起来不像 FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference storageRef = storage.getReferenceFromUrl(fileDetails.getFileUrl());
File rootPath = new File(Environment.getDataDirectory(), "notesApp");
if (!rootPath.exists()) {
rootPath.mkdirs();
}
final File myFile = new File(rootPath,fileDetails.getFileName()+".pdf");
storageRef.getFile(myFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
// Local temp file has been created
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
Log.e("Download Failed: ",exception.toString());
}
});
)。 / p>
在其他语言中,行为有所不同。例如,在C语言中,尽管是静态类型,您仍可以在运行时进行各种操作(例如,将指向字符串的指针复制到包含指向整数数组的指针的变量中)而不会出错。
答案 1 :(得分:1)
C ++中的类型适用于编译器,属于编译时。模板不是 泛型,实际上是编译器生成静态类型特定代码的指令。例如,您可以调用模板参数的静态方法,这在Java中在语法上是不可能的。
C ++运行时类型信息可通过typeid/typeinfo和dynamic_cast运算符(后者可以使用前者)获得。但是即使在编译过程中也可以禁用它,以节省空间。