// Polyglot example: Rust calling Java methods
//
// This example demonstrates how Rust can call Java methods through the
// JVMRS interop API using Interpreter::new_instance, invoke_method,
// get_field_value, set_field_value, and get_object_class.
//
// To run:
// cargo run --example rust_calling_java

use jvmrs::interpreter::Interpreter;
use std::path::PathBuf;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    println!("=== Rust Calling Java Example ===");

    let classpath = vec![PathBuf::from("examples")];
    let mut interpreter = Interpreter::with_classpath(classpath);

    // Load and run Minimal (has main)
    interpreter.load_class_by_name("Minimal")?;
    interpreter.run_main("Minimal")?;

    // Create an instance using reflection
    let obj = interpreter.new_instance("Minimal", &[])?;
    let class_name = interpreter.get_object_class(&obj)?;
    println!("Created instance of class: {}", class_name);

    Ok(())
}
