java 7 new feature

  1. diamond operator.
    泛型只需要在泛型声明时声明具体类型,如:
    List list=new ArrayList<>();
    注意 必须带<>符号。

  2. using primitive,enum or string in switch statements.
    switch语句支持string,比较时使用equal

  3. automatic resource management
    notice that the resource should be managed automaticly must implement java.lang.AutoCloseable interface.
    the AutoCloseable is the parent of java.io.Closeable interface and has just one method close() that would be called by jvm when the control comes out of the try block.
    try语句自动支持对资源对象的回收管理,这些资源对象必须实现AutoCloseable接口,如 java.io.Closeable
    the code template like this :
    try(
    InputStream readIn=new FileInputStream(path);
    OutputStream writeOut=new FileOutputStream(otherPath)
    ){
    // doSmothing
    }

  4. numeric literals with underscores
    notice that the binary literals are also release too.
    数字字面量可以使用下划线隔开,二进制字面量也直接支持,如:
    1_000_000
    0b1001

  5. improved exception handling.
    在catch语句参数中可以捕获多个异常类型,每个异常类型通过符号 | 隔开

  6. new file system api(nio 2.0).
    (1) working with path:a new java.nio.file package consists of classes and interfaces such as path,paths,files,FileSystems and others.
    (2) file change notifications:
    a. create a WatchService,the service consists of a queue to hold watchkeys.
    b. register the director/file you wish to monitor with this WatchService.
    c. while registering,specify the types of events you wish to receive(create,modify,delete events).
    d. when an events occurs,a watchkey is placed into the queue.

  7. fork and join
    ForkJoinPool,RecursiveAction,RecursiveTask.

以下是使用SuperMap iObject Java将JSON数据转换为Feature的示例代码: ```java import com.supermap.data.*; import com.supermap.data.conversion.*; import com.supermap.data.conversion.json.*; public class JsonToFeatureDemo { public static void main(String[] args) { // 创建一个JSON转换对象 JsonConverter converter = new JsonConverter(); // 读取JSON数据文件 String jsonFile = "path/to/json/file.json"; converter.setSourceFile(jsonFile); // 设置目标数据源 Workspace workspace = new Workspace(); Datasource datasource = workspace.getDatasources().open("path/to/datasource.udb"); DatasetVector datasetVector = (DatasetVector) datasource.getDatasets().get("dataset_vector"); converter.setTargetDataSources(datasetVector); // 设置JSON转换参数 JsonConverterParameter parameter = new JsonConverterParameter(); parameter.setImportDataMode(ImportDataMode.CREATE_NEW); parameter.setImportMode(ImportMode.UPDATE_OR_INSERT); converter.setParameters(parameter); try { // 执行转换 boolean success = converter.convert(); if (success) { System.out.println("JSON数据转换为Feature成功!"); } else { System.out.println("JSON数据转换失败!"); } } catch (Exception e) { System.out.println("JSON数据转换出现异常:" + e.getMessage()); } finally { // 释放资源 converter.dispose(); datasetVector.close(); datasource.close(); workspace.close(); } } } ``` 需要注意的是,以上示例代码仅适用于将JSON数据转换为SuperMap iObject Java中的Feature类。如果要将JSON数据转换为其他格式的数据,需要根据不同的数据格式进行相应的转换参数设置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值