# CoerceLuaToJava (Luaj API)
Date: 2015-04-29

## org.luaj.vm2.lib.jse
Class CoerceLuaToJava

    java.lang.Object
      org.luaj.vm2.lib.jse.CoerceLuaToJava

    public class CoerceLuaToJava

extends java.lang.Object

Helper class to coerce values from lua to Java within the luajava library.

This class is primarily used by the `LuajavaLib`, but can also be used directly when working with Java/lua bindings.

To coerce to specific Java values, generally the `toType()` methods on `LuaValue` may be used:

- `LuaValue.toboolean()`
- `LuaValue.tobyte()`
- `LuaValue.tochar()`
- `LuaValue.toshort()`
- `LuaValue.toint()`
- `LuaValue.tofloat()`
- `LuaValue.todouble()`
- `LuaValue.tojstring()`
- `LuaValue.touserdata()`
- `LuaValue.touserdata(Class)`

For data in lua tables, the various methods on `LuaTable` can be used directly to convert data to something more useful.

See Also:
  `LuajavaLib`, `CoerceJavaToLua`

Constructor Summary
`CoerceLuaToJava()`

Method Summary
`static java.lang.Object` `coerce(LuaValue value, java.lang.Class clazz)` Coerce a LuaValue value to a specified java class

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### CoerceLuaToJava

    public CoerceLuaToJava()

Method Detail

### coerce

    public static java.lang.Object coerce(LuaValue value,
                                          java.lang.Class clazz)

  Coerce a LuaValue value to a specified java class

  Parameters:
    `value` - LuaValue to coerce
    `clazz` - Class to coerce into
  Returns:
    Object of type clazz (or a subclass) with the corresponding value.

Copyright © 2007-2015 Luaj.org. All Rights Reserved.