Input
Output

Online java to go(Golang) converter

Java and Go (Golang) are a different type of language. Being used of both in specific scenario and segment.

This code conversion tool is capable of converting some amount of Java code into equivalent rounding code. This instrument is in its infancy stage, its accuracy is less than 50%. Which is constantly being improved.

Notes

Your code must be valid, because we are compiling your code before changing the code.

Your code must depend on java inbuilt package or class or class which is present in test file. It won't work if your code generates any warnings and syntax errors.

Why use those tool?

We do not recommend converting Java code to Go language, this tool may prove useful for those people. Those who know Java and who are learning Golan language. It may also prove useful to a developer trying to convert an existing Java project to equivalent Golang code. that can save your time.

Method overloading example

Java Code
public class Repeat
{
    int a;
    int b;
    Repeat(int a, int b)
    {
        this.a = a;
        this.b = b;
    }
    Repeat()
    {}
    Repeat(int a)
    {
        this.a = 1;
        this.b = 10;
    }
    public void display()
    {
        System.out.println("a:" + a);
        System.out.println("b:" + b);
    }
    public void test()
    {
        System.out.println("a:" + this.a);
    }
    public void test(int c)
    {
        System.out.println("a : " + a + " , b : " + b + " c : " + c);
    }
    public static void main(String[] aa)
    {
        Repeat t = new Repeat();
        Repeat t3 = new Repeat(44);
        t.display();
        t.test();
        t.test(2);
        t3.test(3);
    }
}
Go Code
package main

import "os"
import "strconv"
import "fmt"

type Repeat struct {
     a  int
     b  int
}
func Repeat_1( a  int,  b  int) * Repeat {
    var this * Repeat =  &Repeat{};
    this.a = a;
    this.b = b;
    return this;
}
func Repeat_2() * Repeat {
    var this * Repeat =  &Repeat{};
    return this;
}
func Repeat_3( a  int) * Repeat {
    var this * Repeat =  &Repeat{};
    this.a = 1;
    this.b = 10;
    return this;
}
func (this *Repeat) display() {
    fmt.Println("a:" + strconv.Itoa(this.a));
    fmt.Println("b:" + strconv.Itoa(this.b));
}
func (this *Repeat) test() {
    fmt.Println("a:" + strconv.Itoa(this.a));
}
func (this *Repeat) test_1( c  int) {
    fmt.Println("a : " + strconv.Itoa(this.a) + " , b : " + strconv.Itoa(this.b) + " c : " + strconv.Itoa(c));
}
func (this *Repeat) main_1(aa []string) {
    var  t*  Repeat = Repeat_2();
    var  t3*  Repeat = Repeat_3(44);
    t.display();
    t.test();
    t.test_1(2);
    t3.test_1(3);
}

func main(){
    var task = Repeat{};
    task.main_1(os.Args);// not 100% accurate
}

Array example

// Test Array
public class Task
{
    public static void main(String[] aa)
    {
        int[] a = new int[10];
        int[][] b = {
            {
                1 , 2
            },
            {
                3 , 5
            }
        };
        System.out.println(a.length);
        System.out.println(b.length);
    }
}
Go Code
package main

import "os"
import "fmt"

// Test Array
type Task struct {
}
func Task_1() * Task {
    var this * Task =  &Task{};
    return this;
}
func (this *Task) main_1(aa []string) {
    var a [10]int
    var b  = [][]int{{1, 2}, {3, 5}}
    fmt.Println(len(a));
    fmt.Println(len(b));
}

func main(){
    var task = Task{};
    task.main_1(os.Args);// not 100% accurate
}

Ternary operator transformation

// Ternary operator?
public class Task
{
    public static void main(String[] args)
    {
        int a = 2;
        int b = (a == 2) ? (a + 2 == 4) ? 3 : 23 : a - 2;
        System.out.println(b);
    }
}
Go Code
package main
import "os"
import "fmt"

// Ternary operator?
type Task struct {
}
func Task_1() * Task {
    var this * Task =  &Task{};
    return this;
}
func (this *Task) main_1(args []string) {
    var  a  int = 2;
    var  b  int = (map[bool] int {true: (map[bool] int {true: 3,false:23})[(a + 2 == 4)],false:a - 2})[(a == 2)];
    fmt.Println(b);
}

func main(){
    var task = Task{};
    task.main_1(os.Args);// not 100% accurate
}

Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment