Java开发常用知识
来源:互联网 发布:淘宝客代理分佣系统 编辑:程序博客网 时间:2024/05/22 10:36
getClass()和super.getClass()
getClass().getName() 和super.getClass().getName()的结果是不是一样呢?答案是一样的。
super并没有代表超类的一个引用的能力,只是代表调用父类的方法而已。所以,在子类的方法中,不能这样用System.out.println(super);也不能使用super.super.method()。
super.getClass()只是表示调用父类的方法而已。getClass方法来自Object类,它返回对象在运行时的类型。
如果想获得父类的Class,请用getClass().getSuperclass().getName()
具体请看源码注释:
/** * Returns the unique instance of {@link Class} that represents this * object's class. Note that {@code getClass()} is a special case in that it * actually returns {@code Class<? extends Foo>} where {@code Foo} is the * erasure of the type of the expression {@code getClass()} was called upon. * <p> * As an example, the following code actually compiles, although one might * think it shouldn't: * <p> * <pre>{@code * List<Integer> l = new ArrayList<Integer>(); * Class<? extends List> c = l.getClass();}</pre> * * @return this object's {@code Class} instance. */ public final Class<?> getClass() { return shadow$_klass_; }
/** * Returns the {@code Class} object which represents the superclass of the * class represented by this {@code Class}. If this {@code Class} represents * the {@code Object} class, a primitive type, an interface or void then the * method returns {@code null}. If this {@code Class} represents an array * class then the {@code Object} class is returned. */ public Class<? super T> getSuperclass() { // For interfaces superClass is Object (which agrees with the JNI spec) // but not with the expected behavior here. if (isInterface()) { return null; } else { return superClass; } }
使用FileChannel copy文件
/** * * copy file * * @param src * source file * @param dest * target file * @throws IOException */ public static void copyFile(File src, File dest) throws IOException { FileChannel inChannel = null; FileChannel outChannel = null; try { if (!dest.exists()) { dest.createNewFile(); } inChannel = new FileInputStream(src).getChannel(); outChannel = new FileOutputStream(dest).getChannel(); inChannel.transferTo(0, inChannel.size(), outChannel); } finally { if (inChannel != null) { inChannel.close(); } if (outChannel != null) { outChannel.close(); } } }
删除文件
/** * delete file * * @param file * file * @return true if delete success */ public static boolean deleteFile(File file) { if (!file.exists()) { return true; } if (file.isDirectory()) { File[] files = file.listFiles(); for (File f : files) { deleteFile(f); } } return file.delete(); }
获取文件MD5值
/** * get md5 * * @param file * @return */ public static String getFileMD5(File file) { if (!file.isFile()) { return null; } MessageDigest digest = null; FileInputStream in = null; byte buffer[] = new byte[8192]; int len; try { digest = MessageDigest.getInstance("MD5"); in = new FileInputStream(file); while ((len = in.read(buffer)) != -1) { digest.update(buffer, 0, len); } } catch (Exception e) { Log.e(TAG, "getFileMD5", e); return null; } finally { try { if (in != null) in.close(); } catch (IOException e) { Log.e(TAG, "getFileMD5", e); } } BigInteger bigInt = new BigInteger(digest.digest()); return bigInt.toString(); }
0 0
- Java开发常用知识
- java web开发常用知识1
- Java开发--oracle11g常用知识整理
- vc开发常用知识
- wordpress 开发常用知识
- Webkit开发常用知识
- QML开发常用知识
- JAVA 常用知识
- java 常用知识
- 常用java知识
- java常用知识
- Java常用知识归纳
- 常用java知识
- java常用知识
- Java中常用知识
- java 常用小知识
- WinForm开发常用小知识
- Android开发常用知识总结
- git pull出错解决
- 如何通过CRT进行二次跳转
- mysql创建索引
- 微信开发之ngrok环境搭建
- Redux 入门教程(一):基本用法
- Java开发常用知识
- 读《拖延心理学》的总结和感想
- U盘安装WinXP
- 在 Android Studio 2.2 中愉快地使用 C/C++
- 二十岁出头,你一无所有,但你却拥有一切 【献给像我一样20多岁的年轻人】
- sql SCOPE_IDENTITY()
- Android内核源码级调试环境搭建
- 最长上升子序列
- socket.io client + socketio-netty server简析