AI来实现代码转换!Python转Java,Java转Go不在话下?()

  本篇文章为你整理了AI来实现代码转换!Python转Java,Java转Go不在话下?()的详细内容,包含有 AI来实现代码转换!Python转Java,Java转Go不在话下?,希望能帮助你了解 AI来实现代码转换!Python转Java,Java转Go不在话下?。

  今天看到个有趣的网站,给大家分享一下。

  该网站的功能很神奇,可以实现编程语言的转化。感觉在一些场景之下还是有点作用的,比如你原来跟我一样是做Java的,因为工作需要突然转Go。这个时候用你Java的经验 + 这个工具,或许可以起到一定的帮助作用。

  工具的使用也很简单,只需要在左侧黏贴你想转换的原始代码,然后点击CONVERT CODE,右侧输入框就会转换成目标代码:

  像下面这样更加复杂的代码转换也是不在话下:

  

const fs = require(fs);

 

   const AWS = require(aws-sdk);

   const s3 = new AWS.S3({

   accessKeyId: process.env.AWS_ACCESS_KEY,

   secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY

   const fileName = contacts.csv;

   const uploadFile = () = {

   fs.readFile(fileName, (err, data) = {

   if (err) throw err;

   const params = {

   Bucket: testBucket, // pass your bucket name

   Key: contacts.csv, // file will be saved as testBucket/contacts.csv

   Body: JSON.stringify(data, null, 2)

   s3.upload(params, function(s3Err, data) {

   if (s3Err) throw s3Err

   uploadFile();

  

 

  可以看到其中还包含了aws的内容,居然也能顺利的转成Java

  

import java.io.File;

 

  import java.io.IOException;

  import java.util.Scanner;

  import com.amazonaws.AmazonServiceException;

  import com.amazonaws.SdkClientException;

  import com.amazonaws.auth.profile.ProfileCredentialsProvider;

  import com.amazonaws.services.s3.AmazonS3;

  import com.amazonaws.services.s3.AmazonS3ClientBuilder;

  import com.amazonaws.services.s3.model.ObjectMetadata;

  import com.amazonaws.services.s3.model.PutObjectRequest;

  public class UploadObject {

   public static void main(String[] args) throws IOException {

   String clientRegion = "*** Client region ***";

   String bucketName = "*** Bucket name ***";

   String stringObjKeyName = "*** String object key name ***";

   String fileObjKeyName = "*** File object key name ***";

   String fileName = "*** Path to file to upload ***";

   try {

   AmazonS3 s3Client = AmazonS3ClientBuilder.standard()

   .withRegion(clientRegion)

   .withCredentials(new ProfileCredentialsProvider())

   .build();

   // Upload a text string as a new object.

   s3Client.putObject(bucketName, stringObjKeyName, "Uploaded String Object");

   // Upload a file as a new object with ContentType and title specified.

   PutObjectRequest request = new PutObjectRequest(bucketName, fileObjKeyName, new File(fileName));

   ObjectMetadata metadata = new ObjectMetadata();

   metadata.setContentType("plain/text");

   metadata.addUserMetadata("x-amz-meta-title", "someTitle");

   request.setMetadata(metadata);

   s3Client.putObject(request);

   catch(AmazonServiceException e) {

   // The call was transmitted successfully, but Amazon S3 couldnt process

   // it, so it returned an error response.

   e.printStackTrace();

   catch(SdkClientException e) {

   // Amazon S3 couldnt be contacted for a response, or the client

   // couldnt parse the response from Amazon S3.

   e.printStackTrace();

  

 

  根据官方说明,该工具也是通过AI实现的,是不是很神奇呢?这个到底是怎么实现的呢?有了解的小伙伴留言区一起探讨下吧!

  欢迎关注我的公众号:程序猿DD。第一时间了解前沿行业消息、分享深度技术干货、获取优质学习资源

  以上就是AI来实现代码转换!Python转Java,Java转Go不在话下?()的详细内容,想要了解更多 AI来实现代码转换!Python转Java,Java转Go不在话下?的内容,请持续关注盛行IT软件开发工作室。

郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。

留言与评论(共有 条评论)
   
验证码: