我有Java编程语言的丰富经验.但是我一直想到的一件事是为什么它close() java.io.InputStream或它的子类是必要的?
现在java.io.OutputStream,例如FileOutputStream,在写入文件之后,如果我们不close()输出输出流,那么我们打算在文件中写入的数据将保留在缓冲区中,而不会写入文件.
所以有必要close()的OutputStream.但是,我从来没有过之后任何痛苦的经历不打烊的InputStream.
但是,互联网和书籍上的所有文章仍然说关闭任何流可能是一个InputStream或一个OutputStream.
所以我的问题是,为什么它成为必要close()的InputStream?人们说你可能会面临内存泄漏而不是close()它.那是什么样的内存泄漏?
我有一块帆布.它要求用户从AZ,az或0-9中绘制一个字符.一旦用户绘制了一个字符A,则当前画布对象将保存在画布的arraylist中.弹出另一个空白画布,要求用户绘制B.等等.
程序运行正常.但我想创建一个.ttf包含所有可接受字符的文件.
我在最后显示的画布下方有一个按钮,当点击它时,将从画布的arraylist中提取所有字符并从中创建一个.ttf文件.但是怎么样?
现在,我们知道Java 8在接口中引入了默认和静态方法.
接口最初是用Java引入的,以避免在多重继承中C++中出现的菱形问题.
但是随着Java 8中接口中引入默认方法,Java现在也引入了钻石问题,这在以前的版本中已经避免了.
不会强制要求覆盖默认方法.
但是当钻石问题使用接口时,实现这些接口的类必须覆盖默认方法.
所以现在,我脑子里有三个问题:
有任何好的解释或任何解释链接?
PS我没有在互联网上找到任何包含任何好文章的链接.
他们所说的只是一个抽象的课程让你更具体.
就像在,抽象类可以有构造函数,但接口不能.
所以,我想知道,如果抽象类更具体,并且可以有构造函数,
并且无论如何Java引入了钻石问题,为什么我们现在应该有接口?作为多重继承的独立,抽象类不是很好吗?
我有一个POJO在Person.java文件中:
public class Person {
private String name;
private int age;
public Person(String n, int a) {
name = n;
age = a;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public boolean isAdult() {
return getAge() >= 18;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我有一个Demo.java文件,它创建一个人员列表,并使用流来过滤和打印列表中的内容:
import java.util.*;
public class Demo {
public static void main(String[] args) {
List<Person> people = createPeople();
List<String> names = people.stream()
.filter(person -> person.isAdult())
.map(person -> …Run Code Online (Sandbox Code Playgroud) 因此,我创建了一个接受2个字符串并将其合并的UDF。
我的UDF:// concat_kv.c
#include <my_global.h>
#include <my_sys.h>
#include <mysql.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
typedef unsigned long ulong;
my_bool concat_kv_init(UDF_INIT *initid, UDF_ARGS *args, char *message) {
if(args->arg_count != 2 || args->arg_type[0] != STRING_RESULT || args->arg_type[1] != STRING_RESULT) {
strcpy(message, "concat_kv(): Requires 2 string parameters: Key - Value.");
return 1;
}
return 0;
}
char *concat_kv(UDF_INIT *initid, UDF_ARGS *args, char *result, ulong *length, char *is_null, char *error) {
char *key = (char*)calloc(strlen(args->args[0]), sizeof(char));
char *value = (char*)calloc(strlen(args->args[1]), sizeof(char));
char *res …Run Code Online (Sandbox Code Playgroud) 我编写了一个Python脚本,并且发现Python 3.4并不限制抽象类在Python 2.7.8的情况下被实例化.
这是我在名为的文件中的抽象类Shape.py.
from abc import ABCMeta, abstractmethod
class Shape:
__metaclass__ = ABCMeta # Making the class abstract
def __init__(self):
pass:
@abstractmethod
def getArea(self):
print("You shouldn't have called me.")
return None
Run Code Online (Sandbox Code Playgroud)
现在我创建了另一个继承自abstract类的类Shape:
Filename:Circle.py
from Shape import Shape
class Circle(Shape):
PI = 3.141
def __init__(self, radius=0):
self.radius = radius
def getArea(self): # Overriding it from Shape class
return self.PI * self.radius ** 2
Run Code Online (Sandbox Code Playgroud)
现在在我的Main.py:
from Shape import Shape
from Circle import …Run Code Online (Sandbox Code Playgroud) 我刚刚开始学习 Haskell。我熟悉 C、C++、Java 和 PHP。我仍然不知道如何在 Haskell 中打印从 0 到 10 的数字,而没有putStrLn不同的行。
在 Java 中,我们会这样做:
for(int i=0; i<=10; i++)
System.out.println(i);
Run Code Online (Sandbox Code Playgroud)
然而,Haskell 似乎并不支持这一点。我怎样才能产生相同的结果?
我在我的Mac上创建了一个bash脚本Armstrong.sh.
这是一个检查数字是一个非常强的数字的函数.
# This function works properly
armstrong() {
num=$1 # Making a copy of the received number.
sum=0 # This will store the sum of cubes of each digit from $num
while [ $num -gt 0]; # This loop runs while $num is greater than 0
do
temp=`expr $num % 10` # Extract the last digit of the number
sum=`expr $sum + $temp \* $temp \* $temp` # Cube the last digit and add it to $sum …Run Code Online (Sandbox Code Playgroud) 我试图在C++中重载运算符.
我正在创建一个自定义Stack数据结构.
这是我Stack.h在headers目录中:
/*******************************************************************************
* Stack -- *
* This class will just interface a stack of integers. *
* A stack is a linear data structure. Elements are pushed into stack from the *
* bottom and is popped from the top. *
* *
* Author -- Aditya R.Singh *
* Version -- 1.0 *
* Since -- 2014-06-24 *
*******************************************************************************/
#ifndef STACK_H
#define STACK_H
class Stack {
public:
Stack(); // To initiallize stuff. …Run Code Online (Sandbox Code Playgroud) java ×4
java-8 ×2
abstraction ×1
bash ×1
buffer ×1
c ×1
c++ ×1
fonts ×1
haskell ×1
inputstream ×1
interface ×1
iteration ×1
java-stream ×1
javafx-8 ×1
macos ×1
mysql ×1
outputstream ×1
python ×1
python-3.4 ×1
shell ×1
truetype ×1